From 5198c7ee8d31959083937314200d577ff05c123a Mon Sep 17 00:00:00 2001
From: Eddy Pedroni <epedroni@pm.me>
Date: Wed, 9 Apr 2025 07:21:01 +0200
Subject: Correctly sort log entries

---
 godocs.py | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/godocs.py b/godocs.py
index a207c83..1ba8a06 100644
--- a/godocs.py
+++ b/godocs.py
@@ -7,8 +7,10 @@ from urllib.parse import quote
 from string import capwords
 import shutil
 import tempfile
+import re
 
 DRY = False
+LOG_REGEX = re.compile("(20[0-9]{2})-([0-9]{2})-([0-9]{2})-([A-z\\-]+)\\.md")
 
 @dataclass
 class Page:
@@ -24,6 +26,18 @@ class Page:
         output = output_dir / source.stem / "index.html"
         return Page(title, url, entries, output)
 
+    @staticmethod
+    def order(entries: list[Path]) -> list[Path]:
+        log_entries = []
+        normal_entries = []
+        for e in entries:
+            if LOG_REGEX.fullmatch(e.name):
+                log_entries.append(e)
+            else:
+                normal_entries.append(e)
+
+        return sorted(normal_entries, key=lambda v: v.name) + sorted(log_entries, reverse=True, key=lambda v: v.name)
+
 def renderPageCallback(template_file: Path, stylesheet_url: str) -> Callable[[Page, str], None]:
     """ Callback to process the provided page metadata and output the final page to the filesystem """
     from jinja2 import Environment, FileSystemLoader, select_autoescape
@@ -60,7 +74,7 @@ def collectPages(site_root: Path, site_url: str, output_dir: Path) -> Iterator[P
         
         # Directories are rendered as one page with multiple entries
         if os.path.isdir(page_path):
-            yield Page.create(page_path, sorted(list(page_path.glob("**/*.md"))), site_url, output_dir)
+            yield Page.create(page_path, Page.order(list(page_path.glob("**/*.md"))), site_url, output_dir)
 
         # Single .md files are rendered as single-entry pages
         elif page_path.suffix == ".md":
-- 
cgit v1.2.3