From 5b6edac23604b3f8b2b34088cb070a0523a3ae2e Mon Sep 17 00:00:00 2001 From: CaffeineFueled Date: Sun, 22 Mar 2026 20:44:30 +0100 Subject: [PATCH] tech: ADD allow explicit root index page and path for articles --- config.py | 4 ++++ picopaper.py | 42 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/config.py b/config.py index 0bf0d15..17af7af 100644 --- a/config.py +++ b/config.py @@ -19,6 +19,10 @@ NAVBAR_ITEMS = [ {'text': 'RSS', 'url': '/rss.xml'} ] +# Path settings +BLOGROLL_PATH = "" # Path for the blog roll, e.g. "" (root) or "articles" +ROOT_PAGE = "" # Slug of a page item to use as root index, e.g. "home" (leave empty to use blogroll) - example "home" for "items/2026-01-01_page_home.md" + # Logo settings HIDE_LOGO = False HIDE_TITLE = True diff --git a/picopaper.py b/picopaper.py index 1448e80..8069f6e 100644 --- a/picopaper.py +++ b/picopaper.py @@ -9,7 +9,8 @@ import markdown from config import (BLOG_TITLE, BLOG_DESCRIPTION, THEME, EXCLUDE_SECTIONS_FROM_MAIN, NAVBAR_ITEMS, HIDE_LOGO, HIDE_TITLE, LOGO_PATH, ENABLE_RSS_FEED, RSS_FEED_PATH, - BASE_URL, AUTHOR_NAME, AUTHOR_EMAIL, FEED_MAX_ITEMS) + BASE_URL, AUTHOR_NAME, AUTHOR_EMAIL, FEED_MAX_ITEMS, + BLOGROLL_PATH, ROOT_PAGE) class SSGGGenerator: def __init__(self, items_dir='items', output_dir='output', theme=None, blog_title=None, blog_description=None): @@ -22,6 +23,8 @@ class SSGGGenerator: self.blog_title = blog_title or BLOG_TITLE self.blog_description = blog_description or BLOG_DESCRIPTION self.exclude_sections = EXCLUDE_SECTIONS_FROM_MAIN + self.blogroll_path = BLOGROLL_PATH.strip('/') + self.root_page = ROOT_PAGE self.navbar_items = NAVBAR_ITEMS self.hide_logo = HIDE_LOGO self.hide_title = HIDE_TITLE @@ -159,6 +162,9 @@ class SSGGGenerator: if section_name: title = f"{section_name} - {self.blog_title}" output_path = self.output_dir / 'section' / section_name / 'index.html' + elif self.blogroll_path: + title = self.blog_title + output_path = self.output_dir / self.blogroll_path / 'index.html' else: title = self.blog_title output_path = self.output_dir / 'index.html' @@ -277,6 +283,30 @@ class SSGGGenerator: print(f"✓ Generated {output_path}") + def generate_root_page(self, post, all_posts=None): + """Render a page item at /index.html (used when ROOT_PAGE is set)""" + template = self.env.get_template('post.tmpl') + + html = template.render( + title=f"{post['title']} - {self.blog_title}", + blog_title=self.blog_title, + blog_description=self.blog_description, + navbar_items=self.navbar_items, + post=post, + all_posts=all_posts or [], + hide_logo=self.hide_logo, + hide_title=self.hide_title, + logo_path=self.logo_path, + rss_feed_enabled=ENABLE_RSS_FEED, + rss_feed_path=RSS_FEED_PATH + ) + + output_path = self.output_dir / 'index.html' + with open(output_path, 'w', encoding='utf-8') as f: + f.write(html) + + print(f"✓ Generated {output_path} (root page: {post['slug']})") + def generate_rss_feed(self, posts): """Generate RSS 2.0 feed for main feed posts""" from xml.etree.ElementTree import Element, SubElement, tostring, register_namespace @@ -402,9 +432,17 @@ class SSGGGenerator: if p['type'] != 'page' and p['section'] not in self.exclude_sections] - # Generate main index with filtered posts + # Generate blogroll (at root or at BLOGROLL_PATH) self.generate_index(main_posts, all_posts=main_posts) + # Generate root index from a page item if ROOT_PAGE is set + if self.root_page: + root_post = next((p for p in all_posts if p['slug'] == self.root_page), None) + if root_post: + self.generate_root_page(root_post, all_posts=main_posts) + else: + print(f"Warning: ROOT_PAGE '{self.root_page}' not found, skipping root index") + # Group posts by section (include all posts, not just those in main index) sections = {} for post in all_posts: