mirror of
https://github.com/zensical/zensical.git
synced 2026-05-04 01:50:48 +00:00
fix: watch auto-appended pymdownx.snippets files for changes (#148)
Signed-off-by: Pratyush Sharma <56130065+pratyush618@users.noreply.github.com> Signed-off-by: squidfunk <martin.donath@squidfunk.com> Co-authored-by: squidfunk <martin.donath@squidfunk.com>
This commit is contained in:
@@ -453,6 +453,10 @@ def _apply_defaults(config: dict, path: str) -> dict:
|
||||
# List all source files for mkdocstrings
|
||||
config["source_files"] = _list_sources(config, path)
|
||||
|
||||
# List all snippet files referenced in pymdownx.snippets configuration,
|
||||
# so we can watch them and trigger a rebuild when they change
|
||||
config["snippet_files"] = _list_snippet_files(config, path)
|
||||
|
||||
# Hash all templates, so we rebuild if something changes
|
||||
config["template_hash"] = _hash(_list_templates(config))
|
||||
|
||||
@@ -541,6 +545,27 @@ def _list_sources(config: dict, config_file: str) -> list[tuple[str, int]]:
|
||||
return sorted(files_with_hash)
|
||||
|
||||
|
||||
def _list_snippet_files(
|
||||
config: dict, config_file: str
|
||||
) -> list[tuple[str, int]]:
|
||||
"""List files referenced in pymdownx.snippets auto_append configuration."""
|
||||
snippets_config = config["mdx_configs"].get("pymdownx.snippets", {})
|
||||
auto_append = snippets_config.get("auto_append", [])
|
||||
base_paths = snippets_config.get("base_path", ["."])
|
||||
|
||||
root = Path(config_file).parent.resolve()
|
||||
files_with_mtime = []
|
||||
for file_name in auto_append:
|
||||
for base_path in base_paths:
|
||||
candidate = root.joinpath(base_path, file_name).resolve()
|
||||
if candidate.is_file():
|
||||
mtime = int(os.path.getmtime(candidate))
|
||||
files_with_mtime.append((str(candidate), mtime))
|
||||
break
|
||||
|
||||
return sorted(files_with_mtime)
|
||||
|
||||
|
||||
def _list_templates(config: dict) -> list[tuple[str, int]]:
|
||||
"""List all template files in the theme directories."""
|
||||
dirs = [get_theme_dir()]
|
||||
|
||||
Reference in New Issue
Block a user