use toml for config

This commit is contained in:
Ruidy 2023-06-18 23:18:48 +02:00
parent 255714eca2
commit 2f0faae36b
5 changed files with 15 additions and 23 deletions

View file

@ -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

View file

@ -1,10 +0,0 @@
{
"name": "VillaFleurie",
"staticFilesDir": [
"images",
"js",
"css",
"webfonts"
],
"outDir": "dist"
}

3
config.toml Normal file
View file

@ -0,0 +1,3 @@
name = "VillaFleurie"
static_files = ["images", "js", "css", "webfonts"]
out_dir = "dist"

View file

@ -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"),
)

View file

@ -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…")