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
|
### 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
|
```json
|
||||||
{
|
{
|
||||||
|
|
@ -66,7 +66,7 @@ You can then deploy the site on any platform supporting static sites (Netlify,
|
||||||
- [x] Deploy to VillaFleurie's domain
|
- [x] Deploy to VillaFleurie's domain
|
||||||
- [ ] Find attractions for landing page
|
- [ ] Find attractions for landing page
|
||||||
- [x] Pick real reviews from AirBnB and Booking
|
- [x] Pick real reviews from AirBnB and Booking
|
||||||
- [ ] Optimize images
|
- [x] Optimize images
|
||||||
- [ ] Automate the file search
|
- [ ] Automate the file search
|
||||||
- [x] Extract data out of the template
|
- [x] Extract data out of the template
|
||||||
- [ ] Create a 'all' key for data available in all templates
|
- [ ] 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
|
from dataclasses import dataclass
|
||||||
|
|
||||||
NAME = "name"
|
NAME = "name"
|
||||||
TEMPLATES = "templates"
|
TEMPLATES_DIR = "templates_dir"
|
||||||
TEMPLATES_DIR = "templatesDir"
|
STATIC_FILES = "static_files"
|
||||||
STATIC_FILES_DIR = "staticFilesDir"
|
OUT_DIR = "out_dir"
|
||||||
OUT_DIR = "outDir"
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
class Config:
|
class Config:
|
||||||
name: str
|
name: str
|
||||||
static_files_dir: list[str]
|
static_files: list[str]
|
||||||
out_dir: str
|
out_dir: str
|
||||||
templates_dir: str
|
templates_dir: str
|
||||||
|
|
||||||
|
|
||||||
def load() -> Config:
|
def load() -> Config:
|
||||||
with open("config.json", "r") as f:
|
with open("config.toml", "rb") as f:
|
||||||
raw_config = json.loads(f.read())
|
raw_config = tomllib.load(f)
|
||||||
return Config(
|
return Config(
|
||||||
name=raw_config[NAME],
|
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"),
|
out_dir=raw_config.setdefault(OUT_DIR, "dist"),
|
||||||
templates_dir=raw_config.setdefault(TEMPLATES_DIR, "templates"),
|
templates_dir=raw_config.setdefault(TEMPLATES_DIR, "templates"),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ def main():
|
||||||
try:
|
try:
|
||||||
config = load()
|
config = load()
|
||||||
except FileNotFoundError:
|
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()
|
sys.exit()
|
||||||
|
|
||||||
destination_path = config.out_dir
|
destination_path = config.out_dir
|
||||||
|
|
@ -32,7 +32,7 @@ def main():
|
||||||
fd.write(fs.render(data["template"], data))
|
fd.write(fs.render(data["template"], data))
|
||||||
|
|
||||||
logger.info("⏩ Start copying staticfiles to build")
|
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))
|
shutil.copytree(folder, os.path.join(config.out_dir, folder))
|
||||||
|
|
||||||
logger.info("🎉 Done…")
|
logger.info("🎉 Done…")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue