diff --git a/src/config.py b/src/config.py
index c5233e9..47340df 100644
--- a/src/config.py
+++ b/src/config.py
@@ -8,21 +8,17 @@ from .hooks import hook_call
from .api import api
-def find_project_from_path(project_path: str):
+def find_project_from_path(project_path):
if not path.exists(project_path):
raise Exception("project does not exist")
if not path.exists(path.join(project_path, "config.toml")):
raise Exception(f"cannot find `config.toml` in: {GRAY(project_path)}")
-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_project_config(c) -> Project:
+ return Project(name=c["project"]["name"], version=c["project"]["version"], description=c["project"]["description"])
-def load_tree_config(config) -> Tree:
- t = config["tree"]
+def load_tree_config(c) -> Tree:
+ t = c["tree"]
markdown, static, templates = t["markdown"], t["static"], t["templates"]
draft_dest, release_dest, plugins = t["draft_dest"], t["release_dest"], t["plugins"]
for name, p in [("markdown", markdown), ("static", static), ("templates", templates), ("plugins", plugins)]:
@@ -30,37 +26,26 @@ def load_tree_config(config) -> Tree:
raise FileNotFoundError(f"{name} directory does not exist: {p}")
return Tree(markdown=markdown, static=static, templates=templates, draft_dest=draft_dest, release_dest=release_dest, plugins=plugins)
+def load_webview_config(c) -> Webview:
+ w = c["webview"]
+ return Webview(host=w["host"], port=w["port"], dev_tools=w["dev_tools"], html_path=w["html_path"], static_path=w["static_path"])
-def load_webview_config(config) -> Webview:
- return Webview(
- host = config["webview"].get("host", "localhost"),
- port = config["webview"].get("port", 8866),
- dev_tools = config["webview"].get("dev_tools", False),
- html_path = config["webview"].get("html_path", "/"),
- static_path = config["webview"].get("static_path", "/static"),
- )
+def load_extras_config(c) -> Extras:
+ return Extras(highlight=c["extras"]["highlight"])
-def load_extras_config(config) -> Extras:
- return Extras(
- highlight = config["extras"].get("highlight", "monokai"),
- )
-
-def load_cache_config(config) -> Cache:
- return Cache(
- hash = config["cache"].get("hash", ".hash.cache"),
- )
+def load_cache_config(c) -> Cache:
+ return Cache(hash=c["cache"]["hash"])
def load_config() -> Config:
- config_raw_content = read_file("config.toml")
- config_loaded = loads(config_raw_content)
+ raw = read_file("config.toml")
+ c = loads(raw)
config = Config(
- project = load_project_config(config_loaded),
- tree = load_tree_config(config_loaded),
- webview = load_webview_config(config_loaded),
- extras = load_extras_config(config_loaded),
- cache = load_cache_config(config_loaded),
+ project=load_project_config(c),
+ tree=load_tree_config(c),
+ webview=load_webview_config(c),
+ extras=load_extras_config(c),
+ cache=load_cache_config(c),
)
config = hook_call("on_config_load", config) or config
api.config = config
-
return config