Pi66

merodi
A markdown-based static site generator.
git clone https://git.pi66.xyz/merodi

← back to log

fix: update tracked markdown file based on actual changed path

author: pi66
date: 2026-06-30 17:14
hash: e90787395c6811f4c68db5ac6bc686651ad93ced

Diffstat:

M

src/watcher.py
24 +++++++++++++++++++-----------
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
diff --git a/src/watcher.py b/src/watcher.py
index 0b23910..a32f0b0 100644
--- a/src/watcher.py
+++ b/src/watcher.py
@@ -8,16 +8,22 @@ from .build import compile_md_to_html
 from .log import  warn
 from .errors import fatal

-def reload( file, tree_config, extras_config):
-    global current_url
+current_md_file = None
+
+def reload(changed_path, tree_config, extras_config):
+    global current_md_file
     try:
-        md_relpath = path.relpath(file, tree_config.markdown)
+        if changed_path.endswith(".md"):
+            current_md_file = changed_path
+        if current_md_file is None:
+            return None
+
+        md_relpath = path.relpath(current_md_file, tree_config.markdown)
         dest = path.join(tree_config.dest, md_relpath)
-        if dest.endswith(".md"):
-            dest = dest.removesuffix(".md") + ".html"
-            url = path.relpath(dest, tree_config.dest)
-            compile_md_to_html(file, dest, tree_config, extras_config)
-            return url
+        dest = dest.removesuffix(".md") + ".html"
+        url = path.relpath(dest, tree_config.dest)
+        compile_md_to_html(current_md_file, dest, tree_config, extras_config)
+        return url
     except Exception as e:
         warn(str(e))

@@ -38,7 +44,7 @@ def watch_files(tree_config, extra_config, reload_func:Callable | None=None):
                 return
             last_reload[reload_path] = now
             file = reload( reload_path, tree_config, extra_config)
-            if reload_func: reload_func(file)
+            if reload_func and file: reload_func(file)