Pi66

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

← back to log

refactor: consolidate config loaders into load_config()

author: pi66
date: 2026-07-04 22:56
hash: ad4df864689dd3e26938f0ffc4d1a8359ab04fef

Diffstat:

M

src/config.py
30 +++++++++++++++++++++---------
 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
46
47
48
49
50
51
52
53
54
55
diff --git a/src/config.py b/src/config.py
index 5bdebf4..f69845d 100644
--- a/src/config.py
+++ b/src/config.py
@@ -62,9 +62,14 @@ def find_project_from_path(project_path: str):
     if not path.exists(path.join(project_path, "config.toml")):
         raise Exception(f"cannot find `config.toml` in: {GRAY(project_path)}")

-def load_tree_config() -> Tree:
-    config_raw_content = read_file("config.toml")
-    config = loads(config_raw_content)
+def load_project_config(config) -> Project:
+    return Project(
+        name        = config["project"].get("name", "project"),
+        version     = config["project"].get("version", "0.1.0"),
+        description = config["project"].get("description", "Add your description here"),
+    ) 
+
+def load_tree_config(config) -> Tree:
     markdown  = config["tree"].get("markdown",  "src/md")
     static    = config["tree"].get("static",    "src/static")
     templates = config["tree"].get("templates", "src/templates")
@@ -90,9 +95,7 @@ def load_tree_config() -> Tree:
         plugins   = plugins,
     )

-def load_webview_config() -> Webview:
-    config_raw_content = read_file("config.toml")
-    config = loads(config_raw_content)
+def load_webview_config(config) -> Webview:
     return Webview(
         host        = config["webview"].get("host",        "localhost"),
         port        = config["webview"].get("port",        8866),
@@ -101,9 +104,18 @@ def load_webview_config() -> Webview:
         static_path = config["webview"].get("static_path", "/static"),
     )

-def load_extras_config() -> Extras:
-    config_raw_content = read_file("config.toml")
-    config = loads(config_raw_content)
+def load_extras_config(config) -> Extras:
     return Extras(
         highlight = config["extras"].get("highlight", "monokai"),
     )
+
+def load_config() -> Config:
+    config_raw_content = read_file("config.toml")
+    config = loads(config_raw_content)
+    return Config(
+        project = load_project_config(config),
+        tree    = load_tree_config(config),
+        webview = load_webview_config(config),
+        extras  = load_extras_config(config),
+    )
+