This commit is contained in:
SG
2025-06-17 17:07:00 +03:00
parent 326e5c5edd
commit 0ea2fbeda6
3 changed files with 19 additions and 5 deletions

3
.gitignore vendored
View File

@@ -169,4 +169,5 @@ cython_debug/
#.idea/ #.idea/
public public
content/* content/*
config.yml

View File

@@ -14,7 +14,8 @@ import os, yaml
# THEME = "default" # THEME = "default"
class Config: class Config:
def __init__(self, config_path="config.yml"): def __init__(self):
self.config_path = "config.yml"
self.app_name = "microgen" self.app_name = "microgen"
self.app_description = "Simplistic static site generator" self.app_description = "Simplistic static site generator"
self.app_src_url = f"https://git.exocortex.ru/Exocortex/{self.app_name}" self.app_src_url = f"https://git.exocortex.ru/Exocortex/{self.app_name}"
@@ -23,13 +24,15 @@ class Config:
self.static_dir = 'static' self.static_dir = 'static'
self.output_dir = 'public' self.output_dir = 'public'
self.header_image = 'static/header.jpg' self.header_image = 'static/header.jpg'
self.site_name = "microgen library" self.site_name = f"{self.app_name} library"
self.theme = "default" self.theme = "default"
if os.path.isfile (config_path): if os.path.isfile (self.config_path):
with open(config_path, "r") as f: with open(self.config_path, "r") as f:
config = yaml.safe_load(f) config = yaml.safe_load(f)
if config: if config:
self.update_from_dict(config) self.update_from_dict(config)
else:
self.create_default_config()
def update_from_dict(self, config_dict): def update_from_dict(self, config_dict):
for key, value in config_dict.items(): for key, value in config_dict.items():
@@ -38,4 +41,12 @@ class Config:
def __repr__(self): def __repr__(self):
return f"{self.__dict__}" 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() config = Config()

View File

@@ -0,0 +1,2 @@
site_name: microgen library
theme: default