mirror of
https://github.com/zensical/zensical.git
synced 2026-08-26 09:06:49 +00:00
fix: changes to templates do not trigger rebuild (#103)
Signed-off-by: squidfunk <martin.donath@squidfunk.com>
This commit is contained in:
@@ -118,6 +118,12 @@ def get_theme_dir() -> str:
|
||||
return os.path.join(path, "templates")
|
||||
|
||||
|
||||
def get_custom_theme_dir(config: dict) -> str | None:
|
||||
"""Return the custom theme directory."""
|
||||
path = os.path.dirname(os.path.abspath(__file__))
|
||||
return os.path.join(path, config["theme"]["custom_dir"])
|
||||
|
||||
|
||||
def _apply_defaults(config: dict, path: str) -> dict:
|
||||
"""Apply default settings in configuration.
|
||||
|
||||
@@ -424,6 +430,8 @@ def _apply_defaults(config: dict, path: str) -> dict:
|
||||
config["markdown_extensions"].append("mkdocstrings")
|
||||
config["mdx_configs"]["mkdocstrings"] = mkdocstrings_config
|
||||
|
||||
# Hash all templates, so we rebuild if something changes
|
||||
config["template_hash"] = _hash(_list_templates(config))
|
||||
return config
|
||||
|
||||
|
||||
@@ -456,6 +464,29 @@ def _hash(data: Any) -> int:
|
||||
return int(hash.hexdigest(), 16) % (2**64)
|
||||
|
||||
|
||||
def _list_templates(config: dict) -> list[tuple[str, int]]:
|
||||
"""List all template files in the theme directories."""
|
||||
dirs = [get_theme_dir()]
|
||||
if "custom_dir" in config["theme"]:
|
||||
custom_dir = get_custom_theme_dir(config)
|
||||
if custom_dir is not None:
|
||||
dirs.append(custom_dir)
|
||||
|
||||
# Collect file paths and their mtimes
|
||||
files_with_mtime = []
|
||||
for directory in dirs:
|
||||
for path, _, files in os.walk(directory):
|
||||
if ".icons" in path:
|
||||
continue
|
||||
for file in files:
|
||||
file_path = os.path.join(path, file)
|
||||
mtime = os.path.getsize(file_path)
|
||||
files_with_mtime.append((file_path, mtime))
|
||||
|
||||
# Sort by file path for deterministic order
|
||||
return sorted(files_with_mtime)
|
||||
|
||||
|
||||
def _convert_extra(data: dict | list) -> dict | list:
|
||||
"""Recursively convert all None values in a dictionary or list to empty strings."""
|
||||
if isinstance(data, dict):
|
||||
|
||||
Reference in New Issue
Block a user