Files
hydrogen/config.py
2025-06-17 18:13:47 +03:00

52 lines
1.7 KiB
Python

import os, yaml
# Main config section
#class Config:
# MAIN_PAGE_TITLE = "microgen library"
# APP_NAME = "hydrogen"
# APP_DESCRIPTION = "Simplistic static site generator"
# APP_SRC_URL = f"https://git.exocortex.ru/Exocortex/{APP_NAME}"
# OUTPUT_DIR = 'public'
# TEMPLATES_DIR = 'templates'
# CONTENT_DIR = 'content'
# STATIC_DIR = 'static'
# HEADER_IMAGE = 'static/header.jpg'
# THEME = "default"
class Config:
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}"
self.content_dir = 'content'
self.templates_dir = 'templates'
self.static_dir = 'static'
self.output_dir = 'public'
self.header_image = 'static/header.jpg'
self.site_name = f"{self.app_name} library"
self.theme = "default"
self.debug = False
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)
def update_from_dict(self, config_dict):
for key, value in config_dict.items():
setattr(self, key, value)
def __repr__(self):
return f"{self.__dict__}"
def create_default_config(self):
defaults = {
"site_name": self.site_name,
"theme": "default",
"debug": False
}
with open(self.config_path, mode="w", encoding="utf-8") as f:
yaml.safe_dump(defaults, f)
config = Config()