aboutsummaryrefslogtreecommitdiffstats
path: root/godocs.py
diff options
context:
space:
mode:
authorEddy Pedroni <epedroni@pm.me>2025-04-09 07:21:01 +0200
committerEddy Pedroni <epedroni@pm.me>2025-04-09 07:21:01 +0200
commit5198c7ee8d31959083937314200d577ff05c123a (patch)
treea3f2458ab3e82e1b2b4652b11c8604e7ce95454c /godocs.py
parentd039f2f56e0874866537ab890cfcd14cbb566e76 (diff)
Correctly sort log entries
Diffstat (limited to 'godocs.py')
-rw-r--r--godocs.py16
1 files changed, 15 insertions, 1 deletions
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":