From 56b62f02bcb6bbd2ac3ad7836c766c224d5b6d90 Mon Sep 17 00:00:00 2001 From: Ryan Phillips Date: Sat, 13 Dec 2025 11:38:13 -0600 Subject: [PATCH 1/2] feat: add configurable markdown header ID generation Add optional 'markdown_header_ids' setting to build_settings.json that enables automatic generation of IDs for markdown headers. When enabled, the markdown2 'header-ids' extra is applied during HTML conversion. - Add markdown_header_ids field to SettingsDict TypedDict - Update MarkdownLoader to read and apply header-ids setting - Set default to true in project templates - Update both main and test build_settings.json files --- shodo_ssg/data_loader.py | 13 +++++++++---- shodo_ssg/project_template/build_settings.json | 4 +++- tests/project_template/build_settings.json | 3 ++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/shodo_ssg/data_loader.py b/shodo_ssg/data_loader.py index 895c667..8c96564 100644 --- a/shodo_ssg/data_loader.py +++ b/shodo_ssg/data_loader.py @@ -9,7 +9,7 @@ from json import load, loads from abc import ABC, abstractmethod from io import TextIOWrapper -from typing import TypedDict +from typing import Optional, TypedDict from markdown2 import markdown @@ -28,6 +28,7 @@ class SettingsDict(TypedDict): images_path: str styles_path: str build_dir: str + markdown_header_ids: Optional[bool] = None class DataLoader(ABC): @@ -77,6 +78,7 @@ def __init__(self, settings: SettingsDict): """ super().__init__(settings["markdown_path"]) self.root_path = settings["root_path"] + self.markdown_header_ids = settings.get("markdown_header_ids", None) def list_files(self, sub_dir="partials") -> list[tuple[str]]: """ @@ -103,9 +105,12 @@ def _convert_to_html(self, markdown_file: TextIOWrapper) -> str: """ Takes an open markdown file and converts it to an html string """ - return markdown( - markdown_file.read(), extras=["fenced-code-blocks", "code-friendly"] - ) + md_extras = ["fenced-code-blocks", "code-friendly"] + + if self.markdown_header_ids: + md_extras.append("header-ids") + + return markdown(markdown_file.read(), extras=md_extras) def load_args(self): """ diff --git a/shodo_ssg/project_template/build_settings.json b/shodo_ssg/project_template/build_settings.json index ea88515..1ae7da0 100644 --- a/shodo_ssg/project_template/build_settings.json +++ b/shodo_ssg/project_template/build_settings.json @@ -18,5 +18,7 @@ "===The directory containing files and directories to be copied directly to the root of the build directory===": "", "root_files_path": "src/root", "===The output build directory===": "", - "build_dir": "dist" + "build_dir": "dist", + "===Enable or disable automatic generation of header IDs in markdown files===": "", + "markdown_header_ids": true } \ No newline at end of file diff --git a/tests/project_template/build_settings.json b/tests/project_template/build_settings.json index 50eb86e..e434146 100644 --- a/tests/project_template/build_settings.json +++ b/tests/project_template/build_settings.json @@ -9,5 +9,6 @@ "styles_path": "src/theme/static/styles", "assets_path": "src/theme/static/assets", "root_files_path": "src/root", - "build_dir": "dist" + "build_dir": "dist", + "markdown_header_ids": true } \ No newline at end of file From 71487e75c371be67cb1b62d488be68c64be765cc Mon Sep 17 00:00:00 2001 From: Ryan Phillips Date: Sat, 13 Dec 2025 11:40:58 -0600 Subject: [PATCH 2/2] bump version to 0.0.1a1 Prepare for alpha release by updating version from 0.0.dev4 to 0.0.1a1 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 9f30604..e17c532 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "shodo_ssg" -version = "0.0.dev4" +version = "0.0.1a1" description = "A Python-based static site generator for building sites from Markdown and JSON files" authors = [{name = "Ryan Phillips", email = "ryanphillipssoftware@gmail.com"}] license = {text = "MIT"}