diff options
-rw-r--r-- | godocs.py | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -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": |