diff --git a/README.md b/README.md index 41e6a9d..10ba81f 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ You can use template inheritance. ### Configuration -The configuration file ([config.json](./config.json)) is mandatory and should resemble: +The configuration file ([config.toml](./config.toml)) is mandatory and should resemble: ```json { @@ -66,7 +66,7 @@ You can then deploy the site on any platform supporting static sites (Netlify, - [x] Deploy to VillaFleurie's domain - [ ] Find attractions for landing page - [x] Pick real reviews from AirBnB and Booking -- [ ] Optimize images +- [x] Optimize images - [ ] Automate the file search - [x] Extract data out of the template - [ ] Create a 'all' key for data available in all templates diff --git a/config.json b/config.json deleted file mode 100644 index 1d98306..0000000 --- a/config.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "VillaFleurie", - "staticFilesDir": [ - "images", - "js", - "css", - "webfonts" - ], - "outDir": "dist" -} \ No newline at end of file diff --git a/config.toml b/config.toml new file mode 100644 index 0000000..a481813 --- /dev/null +++ b/config.toml @@ -0,0 +1,3 @@ +name = "VillaFleurie" +static_files = ["images", "js", "css", "webfonts"] +out_dir = "dist" \ No newline at end of file diff --git a/lib/config.py b/lib/config.py index 01639f8..2ebb576 100644 --- a/lib/config.py +++ b/lib/config.py @@ -1,27 +1,26 @@ -import json +import tomllib from dataclasses import dataclass NAME = "name" -TEMPLATES = "templates" -TEMPLATES_DIR = "templatesDir" -STATIC_FILES_DIR = "staticFilesDir" -OUT_DIR = "outDir" +TEMPLATES_DIR = "templates_dir" +STATIC_FILES = "static_files" +OUT_DIR = "out_dir" @dataclass(frozen=True) class Config: name: str - static_files_dir: list[str] + static_files: list[str] out_dir: str templates_dir: str def load() -> Config: - with open("config.json", "r") as f: - raw_config = json.loads(f.read()) + with open("config.toml", "rb") as f: + raw_config = tomllib.load(f) return Config( name=raw_config[NAME], - static_files_dir=raw_config[STATIC_FILES_DIR], + static_files=raw_config[STATIC_FILES], out_dir=raw_config.setdefault(OUT_DIR, "dist"), templates_dir=raw_config.setdefault(TEMPLATES_DIR, "templates"), ) diff --git a/lib/main.py b/lib/main.py index 4aa201d..10ffa53 100644 --- a/lib/main.py +++ b/lib/main.py @@ -13,7 +13,7 @@ def main(): try: config = load() except FileNotFoundError: - logger.error("The configuration file 'config.json' was not found. Please verify it exists at the root level") + logger.error("The configuration file 'config.toml' was not found. Please verify it exists at the root level") sys.exit() destination_path = config.out_dir @@ -32,7 +32,7 @@ def main(): fd.write(fs.render(data["template"], data)) logger.info("⏩ Start copying staticfiles to build") - for folder in config.static_files_dir: + for folder in config.static_files: shutil.copytree(folder, os.path.join(config.out_dir, folder)) logger.info("🎉 Done…")