From 193ba0b4a5ceb87c28a4da56c200caa457a044cf Mon Sep 17 00:00:00 2001 From: veclav talica Date: Sat, 10 Feb 2024 20:58:08 +0500 Subject: [PATCH] sorted by date main feed --- tools/main_page_generator.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tools/main_page_generator.py b/tools/main_page_generator.py index 165edbe..59b07a1 100755 --- a/tools/main_page_generator.py +++ b/tools/main_page_generator.py @@ -25,17 +25,24 @@ page = f"""Personal blog of one {choice(ADJECTIVES)} Veclav Talica. """ -# todo: Sort by date first. +artciles = {} for root, dirs, _ in walk(argv[1]): for d in dirs: metadata = parse_metadata(path.abspath(root + '/' + d + "/page.mmd")) article = urllib.parse.quote(d) - page += ( - f"""[{metadata.get("Title", "No title given! What a clusterfuck!")}](/articles/{article}.html)\n\n""" - f""">{metadata.get("Brief", "")}\n\n""" - ) + artciles[article] = { + "metadata": metadata + } break +for title in sorted(artciles.keys(), key=lambda a: artciles[a]["metadata"].get("Date", time.gmtime(0)), reverse=True): + article = artciles[title] + metadata = article["metadata"] + page += ( + f"""[{metadata.get("Title", "No title given! What a clusterfuck!")}](/articles/{article}.html)\n\n""" + f""">{metadata.get("Brief", "")}\n\n""" + ) + curtime = time.gmtime(int(time.time())) page += f"Last compiled: *{MONTHS[curtime.tm_mon]} {curtime.tm_mday}, {curtime.tm_year} {curtime.tm_hour}:{curtime.tm_min:02d} UTC*\n\n"