diff --git a/.gitignore b/.gitignore index eb078e8..79fabb6 100644 --- a/.gitignore +++ b/.gitignore @@ -169,4 +169,5 @@ cython_debug/ #.idea/ public -content/* \ No newline at end of file +content/* +config.yml diff --git a/config.py b/config.py index c771a35..f7a65e0 100644 --- a/config.py +++ b/config.py @@ -14,7 +14,8 @@ import os, yaml # THEME = "default" class Config: - def __init__(self, config_path="config.yml"): + def __init__(self): + self.config_path = "config.yml" self.app_name = "microgen" self.app_description = "Simplistic static site generator" self.app_src_url = f"https://git.exocortex.ru/Exocortex/{self.app_name}" @@ -23,13 +24,15 @@ class Config: self.static_dir = 'static' self.output_dir = 'public' self.header_image = 'static/header.jpg' - self.site_name = "microgen library" + self.site_name = f"{self.app_name} library" self.theme = "default" - if os.path.isfile (config_path): - with open(config_path, "r") as f: + if os.path.isfile (self.config_path): + with open(self.config_path, "r") as f: config = yaml.safe_load(f) if config: self.update_from_dict(config) + else: + self.create_default_config() def update_from_dict(self, config_dict): for key, value in config_dict.items(): @@ -38,4 +41,12 @@ class Config: def __repr__(self): return f"{self.__dict__}" + def create_default_config(self): + defaults = { + "site_name": self.site_name, + "theme": "default" + } + with open(self.config_path, mode="w", encoding="utf-8") as f: + yaml.safe_dump(defaults, f) + config = Config() \ No newline at end of file diff --git a/config.yml b/config.yml index e69de29..88a8282 100644 --- a/config.yml +++ b/config.yml @@ -0,0 +1,2 @@ +site_name: microgen library +theme: default