From 146c2e25d0be4fb1ce2f60f25fb730b1b202ce0d Mon Sep 17 00:00:00 2001 From: Evan Reichard Date: Fri, 10 Nov 2023 21:59:44 -0500 Subject: [PATCH] [fix] sort most recent first --- vreader/api/common.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/vreader/api/common.py b/vreader/api/common.py index 0503c6e..29e2fa2 100644 --- a/vreader/api/common.py +++ b/vreader/api/common.py @@ -10,12 +10,23 @@ sanitizer = Sanitizer() @bp.route("/", methods=["GET"]) def main_entry(): - + # Get Files directory = str(Config.DATA_PATH) - all_files = os.listdir(directory) markdown_files = [file for file in all_files if file.endswith(".md")] - articles = [parse_filename(file) for file in markdown_files] + + # Get Create Time + file_info_list = [] + for filename in markdown_files: + file_path = os.path.join(directory, filename) + creation_time = os.path.getctime(file_path) + file_info_list.append((filename, creation_time)) + + # Sort Create Time (Recent First) + file_info_list.sort(key=lambda x: x[1], reverse=True) + + # Get Articles + articles = [parse_filename(item[0]) for item in file_info_list] return make_response(render_template("index.html", articles=articles))