fix: creation and listing order
All checks were successful
ci/woodpecker/push/publish Pipeline was successful
All checks were successful
ci/woodpecker/push/publish Pipeline was successful
This commit is contained in:
parent
87ca9ced16
commit
bd2facab1c
1 changed files with 7 additions and 2 deletions
|
@ -17,10 +17,15 @@ def post_file_id(filename: str) -> int:
|
||||||
|
|
||||||
def get_posts() -> list[str]:
|
def get_posts() -> list[str]:
|
||||||
"""get posts list"""
|
"""get posts list"""
|
||||||
return [
|
posts = [
|
||||||
os_path.join(Config.data_dir, basename) for basename in listdir(Config.data_dir)
|
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:
|
def get_post(filename: str) -> str | None:
|
||||||
"""get a post"""
|
"""get a post"""
|
||||||
|
@ -51,7 +56,7 @@ def fresh_file_id() -> int:
|
||||||
# use the latest file as the reference and increment the ID
|
# use the latest file as the reference and increment the ID
|
||||||
filename = 0
|
filename = 0
|
||||||
if len(paths) > filename:
|
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
|
# add 1 to the chosen id
|
||||||
filename = post_file_id(chosen) + 1
|
filename = post_file_id(chosen) + 1
|
||||||
|
|
Loading…
Reference in a new issue