diff --git a/src/routes/index.py b/src/routes/index.py index 7d5a7e6..43f01e2 100644 --- a/src/routes/index.py +++ b/src/routes/index.py @@ -1,7 +1,9 @@ -from os import listdir, path as os_path -from werkzeug import Response +from os import path as os_path + from config import Config from flask import Blueprint, flash, redirect, render_template, request +from utils.misc import get_posts +from werkzeug import Response name = __name__.split(".")[-1] router = Blueprint(name, __name__) @@ -10,7 +12,12 @@ router = Blueprint(name, __name__) @router.route("/") def index() -> str: """index page""" - return render_template("index.html", config=Config, page_name=name) + return render_template( + "index.html", + config=Config, + page_name=name, + posts=[p.split("/")[-1][:-4] for p in get_posts()], + ) @router.route("/", methods=["POST"]) @@ -20,10 +27,7 @@ def new_post() -> Response: content = request.form.get("p") if content: # finding all posts - paths = [ - os_path.join(Config.data_dir, basename) - for basename in listdir(Config.data_dir) - ] + paths = get_posts() # finding an appropriate filename filename = 0 diff --git a/src/static/css/style.css b/src/static/css/style.css index 0d9fb13..2fd7fe7 100644 --- a/src/static/css/style.css +++ b/src/static/css/style.css @@ -69,3 +69,16 @@ aside textarea { min-width: 20em; min-height: 7em; } + +/* index listing of posts */ +ul { + list-style: none; +} + +li { + padding-bottom: 1em; +} + +li a { + color: inherit; +} diff --git a/src/templates/index.html b/src/templates/index.html index b9aaf5f..3741eab 100644 --- a/src/templates/index.html +++ b/src/templates/index.html @@ -12,7 +12,11 @@

{{ "".join(get_flashed_messages()) | safe }}

posts

- + diff --git a/src/utils/misc.py b/src/utils/misc.py new file mode 100644 index 0000000..39b1d78 --- /dev/null +++ b/src/utils/misc.py @@ -0,0 +1,10 @@ +from os import listdir +from os import path as os_path + +from config import Config + + +def get_posts(): + return [ + os_path.join(Config.data_dir, basename) for basename in listdir(Config.data_dir) + ]