updates
This commit is contained in:
@@ -26,17 +26,16 @@ else:
|
|||||||
if Path(f"themes/{config.theme}/templates").exists():
|
if Path(f"themes/{config.theme}/templates").exists():
|
||||||
# Use the templates from the initialized site instance and the installed theme
|
# Use the templates from the initialized site instance and the installed theme
|
||||||
jinja_env_dir = f"themes/{config.theme}/templates"
|
jinja_env_dir = f"themes/{config.theme}/templates"
|
||||||
print("USING LOCALLY INITIALIZED THEMES")
|
logger.debug(f"Using locally initialized templates from {jinja_env_dir}")
|
||||||
else:
|
else:
|
||||||
# Use default templates from the default theme shipped with the app
|
# Use default templates from the default theme shipped with the app
|
||||||
# i.e. PyInstaller-packed single executable
|
# i.e. PyInstaller-packed single executable
|
||||||
print("USING DEFAULT THEMES")
|
logger.debug("Using shipped default temlpates.")
|
||||||
jinja_env_dir = f"{base_dir}/themes/default/templates"
|
jinja_env_dir = f"{base_dir}/themes/default/templates"
|
||||||
env = Environment(loader=FileSystemLoader(f"{jinja_env_dir}"))
|
env = Environment(loader=FileSystemLoader(f"{jinja_env_dir}"))
|
||||||
env.globals['header_image'] = f"{base_dir}/themes/{config.theme}/static/images/header.jpg"
|
env.globals['header_image'] = f"{base_dir}/themes/{config.theme}/static/images/header.jpg"
|
||||||
index_template = env.get_template("index.html")
|
index_template = env.get_template("index.html")
|
||||||
content_item_template = env.get_template("content_item.html")
|
content_item_template = env.get_template("content_item.html")
|
||||||
print(env.loader.searchpath)
|
|
||||||
|
|
||||||
class ContentItem:
|
class ContentItem:
|
||||||
def render_content(self, categories, target_file = False):
|
def render_content(self, categories, target_file = False):
|
||||||
@@ -120,7 +119,11 @@ class Site:
|
|||||||
self.categories = defaultdict(list)
|
self.categories = defaultdict(list)
|
||||||
|
|
||||||
def init_site(self):
|
def init_site(self):
|
||||||
|
if os.path.isdir('.') and os.listdir('.'):
|
||||||
|
logger.error("Current directory is not empty.")
|
||||||
|
sys.exit(1)
|
||||||
logger.info("Initializing new site")
|
logger.info("Initializing new site")
|
||||||
|
config.create_default_config()
|
||||||
# Create directories
|
# Create directories
|
||||||
for subdir in [self.content_dir]:
|
for subdir in [self.content_dir]:
|
||||||
os.makedirs(subdir, exist_ok=True)
|
os.makedirs(subdir, exist_ok=True)
|
||||||
|
|||||||
@@ -26,13 +26,12 @@ class Config:
|
|||||||
self.header_image = 'static/header.jpg'
|
self.header_image = 'static/header.jpg'
|
||||||
self.site_name = f"{self.app_name} library"
|
self.site_name = f"{self.app_name} library"
|
||||||
self.theme = "default"
|
self.theme = "default"
|
||||||
|
self.debug = False
|
||||||
if os.path.isfile (self.config_path):
|
if os.path.isfile (self.config_path):
|
||||||
with open(self.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():
|
||||||
@@ -44,7 +43,8 @@ class Config:
|
|||||||
def create_default_config(self):
|
def create_default_config(self):
|
||||||
defaults = {
|
defaults = {
|
||||||
"site_name": self.site_name,
|
"site_name": self.site_name,
|
||||||
"theme": "default"
|
"theme": "default",
|
||||||
|
"debug": False
|
||||||
}
|
}
|
||||||
with open(self.config_path, mode="w", encoding="utf-8") as f:
|
with open(self.config_path, mode="w", encoding="utf-8") as f:
|
||||||
yaml.safe_dump(defaults, f)
|
yaml.safe_dump(defaults, f)
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
|
debug: false
|
||||||
site_name: microgen library
|
site_name: microgen library
|
||||||
theme: default
|
theme: default
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ from config import config
|
|||||||
|
|
||||||
LOG_TO = sys.stdout
|
LOG_TO = sys.stdout
|
||||||
LOG_LEVEL = logging.INFO
|
LOG_LEVEL = logging.INFO
|
||||||
|
if config.debug == True:
|
||||||
|
LOG_LEVEL = logging.DEBUG
|
||||||
|
|
||||||
logger = logging.getLogger(config.app_name)
|
logger = logging.getLogger(config.app_name)
|
||||||
logger.setLevel(LOG_LEVEL)
|
logger.setLevel(LOG_LEVEL)
|
||||||
|
|||||||
Reference in New Issue
Block a user