mirror of
https://github.com/rjNemo/vf-site
synced 2026-06-06 01:16:38 +00:00
refactor
This commit is contained in:
parent
0825956100
commit
5e351e4cd4
1 changed files with 10 additions and 6 deletions
16
lib/main.py
16
lib/main.py
|
|
@ -27,12 +27,7 @@ def main():
|
|||
for page in os.scandir(config.templates_dir):
|
||||
if page.is_file():
|
||||
with open(os.path.join(destination_path, page.name), "w") as fd:
|
||||
data_file_path = os.path.join(config.data_dir, f"{page.name.split('.')[0]}.toml")
|
||||
data = {}
|
||||
if os.path.isfile(data_file_path):
|
||||
with open(data_file_path, "rb") as f:
|
||||
data = tomllib.load(f)
|
||||
logger.debug(data)
|
||||
data = parse_data(page, config.data_dir)
|
||||
logger.info(f"📃Render '{page.name}'")
|
||||
fd.write(fs.render(page.name, data))
|
||||
|
||||
|
|
@ -42,6 +37,15 @@ def main():
|
|||
logger.info("🎉 Done…")
|
||||
|
||||
|
||||
def parse_data(page: os.DirEntry, data_dir: str) -> dict:
|
||||
data_file_path = os.path.join(data_dir, f"{page.name.split('.')[0]}.toml")
|
||||
data = {}
|
||||
if os.path.isfile(data_file_path):
|
||||
with open(data_file_path, "rb") as f:
|
||||
data = tomllib.load(f)
|
||||
return data
|
||||
|
||||
|
||||
def clean_dist(destination_path: str):
|
||||
if os.path.exists(destination_path) and os.path.isdir(destination_path):
|
||||
shutil.rmtree(destination_path)
|
||||
|
|
|
|||
Loading…
Reference in a new issue