2021-06-23 21:26:35 +01:00
|
|
|
### Generation helper for category pages
|
|
|
|
|
2021-06-25 04:52:22 +01:00
|
|
|
from .. import file as util_file
|
|
|
|
from .. import csv as util_csv
|
|
|
|
import shutil
|
|
|
|
import os
|
2021-06-23 21:26:35 +01:00
|
|
|
|
2021-06-25 04:52:22 +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 04:52:22 +01:00
|
|
|
"""
|
|
|
|
|
2021-06-25 21:13:36 +01:00
|
|
|
categoryIdName = "tk_category_dashname"
|
|
|
|
categories = util_csv.dictReaderMultiRow("../csv/categories.csv", categoryIdName)
|
2021-06-25 04:52:22 +01:00
|
|
|
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]}"
|
2021-06-25 04:52:22 +01:00
|
|
|
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])
|