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 os import path as os_path
from werkzeug import Response
from config import Config from config import Config
from flask import Blueprint, flash, redirect, render_template, request from flask import Blueprint, flash, redirect, render_template, request
from utils.misc import get_posts
from werkzeug import Response
name = __name__.split(".")[-1] name = __name__.split(".")[-1]
router = Blueprint(name, __name__) router = Blueprint(name, __name__)
@ -10,7 +12,12 @@ router = Blueprint(name, __name__)
@router.route("/") @router.route("/")
def index() -> str: def index() -> str:
"""index page""" """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"]) @router.route("/", methods=["POST"])
@ -20,10 +27,7 @@ def new_post() -> Response:
content = request.form.get("p") content = request.form.get("p")
if content: if content:
# finding all posts # finding all posts
paths = [ paths = get_posts()
os_path.join(Config.data_dir, basename)
for basename in listdir(Config.data_dir)
]
# finding an appropriate filename # finding an appropriate filename
filename = 0 filename = 0

View file

@ -69,3 +69,16 @@ aside textarea {
min-width: 20em; min-width: 20em;
min-height: 7em; 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> <p>{{ "".join(get_flashed_messages()) | safe }}</p>
<h3>posts</h3> <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> </main>
</body> </body>
</html> </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)
]