index listing of posts
All checks were successful
ci/woodpecker/push/publish Pipeline was successful

This commit is contained in:
Mylloon 2023-12-22 02:21:43 +01:00
parent 2c74602a21
commit 008ecb7636
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
4 changed files with 39 additions and 8 deletions

View file

@ -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

View file

@ -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;
}

View file

@ -12,7 +12,11 @@
<p>{{ "".join(get_flashed_messages()) | safe }}</p>
<h3>posts</h3>
<!-- TODO: list of clickable posts -->
<ul>
{% for p in posts: %}
<li><a href="read/{{ p }}">{{ p }}.txt</a></li>
{% endfor %}
</ul>
</main>
</body>
</html>

10
src/utils/misc.py Normal file
View file

@ -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)
]