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"