fix: creation and listing order
All checks were successful
ci/woodpecker/push/publish Pipeline was successful

This commit is contained in:
Mylloon 2023-12-22 03:56:03 +01:00
parent 87ca9ced16
commit bd2facab1c
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -17,10 +17,15 @@ def post_file_id(filename: str) -> int:
def get_posts() -> list[str]:
"""get posts list"""
return [
posts = [
os_path.join(Config.data_dir, basename) for basename in listdir(Config.data_dir)
]
# sort from new to old
posts.sort(key=post_file_id, reverse=True)
return posts
def get_post(filename: str) -> str | None:
"""get a post"""
@ -51,7 +56,7 @@ def fresh_file_id() -> int:
# use the latest file as the reference and increment the ID
filename = 0
if len(paths) > filename:
chosen = max(iter(paths), key=os_path.getmtime)
chosen = max(iter(paths), key=post_file_id)
# add 1 to the chosen id
filename = post_file_id(chosen) + 1