tech: ADD allow explicit root index page and path for articles
This commit is contained in:
parent
cdbdc7e392
commit
a8b1f312bc
2 changed files with 44 additions and 2 deletions
|
|
@ -19,6 +19,10 @@ NAVBAR_ITEMS = [
|
||||||
{'text': 'RSS', 'url': '/rss.xml'}
|
{'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
|
# Logo settings
|
||||||
HIDE_LOGO = False
|
HIDE_LOGO = False
|
||||||
HIDE_TITLE = True
|
HIDE_TITLE = True
|
||||||
|
|
|
||||||
42
picopaper.py
42
picopaper.py
|
|
@ -9,7 +9,8 @@ import markdown
|
||||||
from config import (BLOG_TITLE, BLOG_DESCRIPTION, THEME, EXCLUDE_SECTIONS_FROM_MAIN,
|
from config import (BLOG_TITLE, BLOG_DESCRIPTION, THEME, EXCLUDE_SECTIONS_FROM_MAIN,
|
||||||
NAVBAR_ITEMS, HIDE_LOGO, HIDE_TITLE, LOGO_PATH,
|
NAVBAR_ITEMS, HIDE_LOGO, HIDE_TITLE, LOGO_PATH,
|
||||||
ENABLE_RSS_FEED, RSS_FEED_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:
|
class SSGGGenerator:
|
||||||
def __init__(self, items_dir='items', output_dir='output', theme=None, blog_title=None, blog_description=None):
|
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_title = blog_title or BLOG_TITLE
|
||||||
self.blog_description = blog_description or BLOG_DESCRIPTION
|
self.blog_description = blog_description or BLOG_DESCRIPTION
|
||||||
self.exclude_sections = EXCLUDE_SECTIONS_FROM_MAIN
|
self.exclude_sections = EXCLUDE_SECTIONS_FROM_MAIN
|
||||||
|
self.blogroll_path = BLOGROLL_PATH.strip('/')
|
||||||
|
self.root_page = ROOT_PAGE
|
||||||
self.navbar_items = NAVBAR_ITEMS
|
self.navbar_items = NAVBAR_ITEMS
|
||||||
self.hide_logo = HIDE_LOGO
|
self.hide_logo = HIDE_LOGO
|
||||||
self.hide_title = HIDE_TITLE
|
self.hide_title = HIDE_TITLE
|
||||||
|
|
@ -159,6 +162,9 @@ class SSGGGenerator:
|
||||||
if section_name:
|
if section_name:
|
||||||
title = f"{section_name} - {self.blog_title}"
|
title = f"{section_name} - {self.blog_title}"
|
||||||
output_path = self.output_dir / 'section' / section_name / 'index.html'
|
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:
|
else:
|
||||||
title = self.blog_title
|
title = self.blog_title
|
||||||
output_path = self.output_dir / 'index.html'
|
output_path = self.output_dir / 'index.html'
|
||||||
|
|
@ -277,6 +283,30 @@ class SSGGGenerator:
|
||||||
|
|
||||||
print(f"✓ Generated {output_path}")
|
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):
|
def generate_rss_feed(self, posts):
|
||||||
"""Generate RSS 2.0 feed for main feed posts"""
|
"""Generate RSS 2.0 feed for main feed posts"""
|
||||||
from xml.etree.ElementTree import Element, SubElement, tostring, register_namespace
|
from xml.etree.ElementTree import Element, SubElement, tostring, register_namespace
|
||||||
|
|
@ -402,9 +432,17 @@ class SSGGGenerator:
|
||||||
if p['type'] != 'page'
|
if p['type'] != 'page'
|
||||||
and p['section'] not in self.exclude_sections]
|
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)
|
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)
|
# Group posts by section (include all posts, not just those in main index)
|
||||||
sections = {}
|
sections = {}
|
||||||
for post in all_posts:
|
for post in all_posts:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue