mirror of
https://github.com/rjNemo/vf-site
synced 2026-06-06 01:16:38 +00:00
use toml for config
This commit is contained in:
parent
255714eca2
commit
2f0faae36b
5 changed files with 15 additions and 23 deletions
|
|
@ -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
|
||||
|
|
|
|||
10
config.json
10
config.json
|
|
@ -1,10 +0,0 @@
|
|||
{
|
||||
"name": "VillaFleurie",
|
||||
"staticFilesDir": [
|
||||
"images",
|
||||
"js",
|
||||
"css",
|
||||
"webfonts"
|
||||
],
|
||||
"outDir": "dist"
|
||||
}
|
||||
3
config.toml
Normal file
3
config.toml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
name = "VillaFleurie"
|
||||
static_files = ["images", "js", "css", "webfonts"]
|
||||
out_dir = "dist"
|
||||
|
|
@ -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"),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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…")
|
||||
|
|
|
|||
Loading…
Reference in a new issue