mirror of
https://github.com/rjNemo/vf-site
synced 2026-06-06 01:16:38 +00:00
automatically handle static files
This commit is contained in:
parent
43f5982d5d
commit
04006bb736
4 changed files with 22 additions and 1 deletions
|
|
@ -22,6 +22,7 @@ The configuration file ([config.json](./config.json)) is mandatory and should re
|
|||
"contact.html",
|
||||
"reservation.html"
|
||||
],
|
||||
"staticFiles": [],
|
||||
"outDir": "dist"
|
||||
}
|
||||
```
|
||||
|
|
|
|||
|
|
@ -7,5 +7,11 @@
|
|||
"contact.html",
|
||||
"reservation.html"
|
||||
],
|
||||
"staticFiles": [
|
||||
"images",
|
||||
"js",
|
||||
"css",
|
||||
"webfonts"
|
||||
],
|
||||
"outDir": "dist"
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ from typing import TypedDict
|
|||
class Config(TypedDict):
|
||||
name: str
|
||||
templates: list[str]
|
||||
staticFiles: list[str]
|
||||
outDir: str
|
||||
|
||||
|
||||
|
|
|
|||
15
lib/main.py
15
lib/main.py
|
|
@ -1,3 +1,5 @@
|
|||
import os
|
||||
import shutil
|
||||
import sys
|
||||
from os import path
|
||||
|
||||
|
|
@ -15,11 +17,22 @@ def main():
|
|||
sys.exit()
|
||||
|
||||
data = {}
|
||||
destination_path = config["outDir"]
|
||||
|
||||
logger.info(f"🏁 Start building {config['name']}")
|
||||
|
||||
if os.path.exists(destination_path) and os.path.isdir(destination_path):
|
||||
shutil.rmtree(destination_path)
|
||||
os.mkdir(destination_path)
|
||||
|
||||
for template in config["templates"]:
|
||||
logger.info(f"📃Render '{template}'")
|
||||
with open(path.join(config["outDir"], template), "w") as f:
|
||||
with open(path.join(destination_path, template), "w") as f:
|
||||
f.write(render(template, data.get(template)))
|
||||
|
||||
logger.info("⏩ Start copying staticfiles to build")
|
||||
for folder in config["staticFiles"]:
|
||||
shutil.copytree(folder, f"{config['outDir']}/{folder}")
|
||||
logger.info("🎉 Done…")
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue