mirror of
https://github.com/rjNemo/vf-site
synced 2026-06-12 12:06:39 +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",
|
"contact.html",
|
||||||
"reservation.html"
|
"reservation.html"
|
||||||
],
|
],
|
||||||
|
"staticFiles": [],
|
||||||
"outDir": "dist"
|
"outDir": "dist"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -7,5 +7,11 @@
|
||||||
"contact.html",
|
"contact.html",
|
||||||
"reservation.html"
|
"reservation.html"
|
||||||
],
|
],
|
||||||
|
"staticFiles": [
|
||||||
|
"images",
|
||||||
|
"js",
|
||||||
|
"css",
|
||||||
|
"webfonts"
|
||||||
|
],
|
||||||
"outDir": "dist"
|
"outDir": "dist"
|
||||||
}
|
}
|
||||||
|
|
@ -5,6 +5,7 @@ from typing import TypedDict
|
||||||
class Config(TypedDict):
|
class Config(TypedDict):
|
||||||
name: str
|
name: str
|
||||||
templates: list[str]
|
templates: list[str]
|
||||||
|
staticFiles: list[str]
|
||||||
outDir: str
|
outDir: str
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
15
lib/main.py
15
lib/main.py
|
|
@ -1,3 +1,5 @@
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
from os import path
|
from os import path
|
||||||
|
|
||||||
|
|
@ -15,11 +17,22 @@ def main():
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
data = {}
|
data = {}
|
||||||
|
destination_path = config["outDir"]
|
||||||
|
|
||||||
logger.info(f"🏁 Start building {config['name']}")
|
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"]:
|
for template in config["templates"]:
|
||||||
logger.info(f"📃Render '{template}'")
|
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)))
|
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…")
|
logger.info("🎉 Done…")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue