Mostly works! Image loading and caching seems slow

This commit is contained in:
2025-02-16 20:36:13 -05:00
parent de565fce4f
commit b2ed4cc4e5
14 changed files with 625 additions and 6 deletions

10
src/config/args.py Normal file
View File

@ -0,0 +1,10 @@
import argparse
def create_parser():
parser = argparse.ArgumentParser(description="foldsite is a dynamic site generator")
parser.add_argument(
"--config", type=str, default="config.toml", help="config file path"
)
return parser

50
src/config/config.py Normal file
View File

@ -0,0 +1,50 @@
from pathlib import Path
import tomllib
CONTENT_DIR = None
TEMPLATES_DIR = None
STYLES_DIR = None
class Configuration:
def __init__(self, config_path):
self.config_path = config_path
self.content_dir: Path = None
self.templates_dir: Path = None
self.styles_dir: Path = None
def load_config(self):
try:
with open(self.config_path, "rb") as f:
self.config_data = tomllib.load(f)
except FileNotFoundError:
raise FileNotFoundError(f"Config file not found at {self.config_path}")
except tomllib.TOMLDecodeError:
raise tomllib.TOMLDecodeError(f"Config file at {self.config_path} is not valid TOML")
paths = self.config_data.get("paths", {})
if not paths:
raise ValueError("Config file does not contain paths section")
self.content_dir = paths.get("content_dir")
if not self.content_dir:
raise ValueError("Config file does not contain content_dir path")
self.content_dir = Path(self.content_dir)
self.templates_dir = paths.get("templates_dir")
if not self.templates_dir:
raise ValueError("Config file does not contain templates_dir path")
self.templates_dir = Path(self.templates_dir)
self.styles_dir = paths.get("styles_dir")
if not self.styles_dir:
raise ValueError("Config file does not contain styles_dir path")
self.styles_dir = Path(self.styles_dir)
def set_globals(self):
global CONTENT_DIR, TEMPLATES_DIR, STYLES_DIR
CONTENT_DIR = self.content_dir
TEMPLATES_DIR = self.templates_dir
STYLES_DIR = self.styles_dir