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