From bd2facab1cfee9f05869e1c4a5e7279c26542a2e Mon Sep 17 00:00:00 2001 From: Mylloon Date: Fri, 22 Dec 2023 03:56:03 +0100 Subject: [PATCH] fix: creation and listing order --- src/utils/misc.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/utils/misc.py b/src/utils/misc.py index d0c596e..e2ba64c 100644 --- a/src/utils/misc.py +++ b/src/utils/misc.py @@ -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