Pi66

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

← back to log

refactor:simplify walk/build orchestration

author: pixel
date: 2026-07-22 09:36
hash: aa8995bead3e56b6bc403e88c0ebc7ce65e05b3a

Diffstat:

M

src/build.py
23 ++++++++++++------------------
 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
42
43
44
45
diff --git a/src/build.py b/src/build.py
index 9cf01a3..dac49a1 100644
--- a/src/build.py
+++ b/src/build.py
@@ -157,19 +157,15 @@ def compile_file(md_file, html_dest, config=None, plugins=None, force=False):
 def walk_and_build(config, plugins, dest, force_all=False):
     md_path = config.tree.markdown
     hook_call("on_walk_start", config)
-    files = []
-    for parent, _, filenames in walk(md_path):
-        for filename in filenames:
-            files.append(path.join(parent, filename))
+    files = [path.join(p, f) for p, _, fs in walk(md_path) for f in fs]
     for md_file in progress(files, "Building"):
         hook_call("on_walk_file", md_file)
         md_relpath = path.relpath(md_file, md_path)
-        if is_dotfile(md_relpath): continue
-        html_dest = path.join(dest, md_relpath)
-        if html_dest.endswith(".md"):
-            html_dest = html_dest.removesuffix(".md") + ".html"
-        source_file = readlink(md_file) if path.islink(md_file) else md_file
-        compile_file(source_file, html_dest, config, plugins, force=force_all)
+        if is_dotfile(md_relpath):
+            continue
+        html_dest = path.join(dest, md_relpath.removesuffix(".md") + ".html")
+        source = readlink(md_file) if path.islink(md_file) else md_file
+        compile_file(source, html_dest, config, plugins, force=force_all)
     hook_call("on_walk_end", config)

 def build_all(config, plugins, dest):
@@ -197,11 +193,10 @@ def validate_build(config, plugins):

 def build_if_file(project_path, file):
     if project_path:
-        raise ValueError("Please specify either a project path or a file path, not both.")
-    elif len(file) != 2:
+        raise ValueError("Specify either a project path or a file path, not both.")
+    if len(file) != 2:
         raise ValueError("A file path must include exactly a source and a destination.")
-    else:
-        compile_file(file[0], file[1])
+    compile_file(file[0], file[1])

 def build(mode, project_path, file, validate=False, force=False):
     try: