updates
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -170,3 +170,4 @@ cython_debug/
|
|||||||
|
|
||||||
public
|
public
|
||||||
content/*
|
content/*
|
||||||
|
config.yml
|
||||||
|
|||||||
19
config.py
19
config.py
@@ -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()
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
site_name: microgen library
|
||||||
|
theme: default
|
||||||
|
|||||||
Reference in New Issue
Block a user