paceboard/scripts/utils/gen/categories.py

40 lines
1.3 KiB
Python
Raw Normal View History

2021-06-23 21:26:35 +01:00
### Generation helper for category pages
from .. import file as util_file
from .. import csv as util_csv
import shutil
import os
2021-06-23 21:26:35 +01:00
def generate(templatedir, destinationdir, templateFilename):
"""Main generation function for category page generation helper.
2021-06-25 21:13:36 +01:00
templatedir -- the relative path of the template html file's directory\n
destinationpath -- the directory where category paths should be generated\n
templateFilename -- the filename of the category template (always category.html)\n
"""
2021-06-25 21:13:36 +01:00
categoryIdName = "tk_category_dashname"
categories = util_csv.dictReaderMultiRow("../csv/categories.csv", categoryIdName)
config = util_csv.dictReaderFirstRow("../csv/config.csv")
for category in categories:
2021-06-25 21:13:36 +01:00
path = f"{destinationdir}/{categories[category][categoryIdName]}"
currentDir = os.getcwd()
os.makedirs(path, exist_ok=True)
shutil.copy(
f"{currentDir}/{templatedir}/{templateFilename}",
f"{currentDir}/{path}/index.html",
)
for key in categories[category]:
util_file.replaceTextInFile(
f"{path}/index.html", key, categories[category][key]
)
for key in config.keys():
util_file.replaceTextInFile(f"{path}/index.html", key, config[key])