### Generation helper for index.html
from .. import file as util_file
from .. import csv as util_csv
import shutil
def generate(templatedir, destinationdir, templateFilename):
"""Main generation function for index.html generation helper.
templatedir -- the relative path of the template html file's directory
destinationpath -- the directory where index.html should be generated
filename -- the filename of the index template (always index.html)
"""
shutil.copy(f"{templatedir}/{templateFilename}", destinationdir)
idName = "tk_category_dashname"
categories = util_csv.dictReaderMultiRow("../csv/categories.csv", idName)
config = util_csv.dictReaderFirstRow("../csv/config.csv")
for key in config.keys():
util_file.replaceTextInFile(f"{destinationdir}/index.html", key, config[key])
tk_category_dashname = "tk_category_dashname"
tk_category_name = "tk_category_name"
for category in categories:
util_file.replaceTextInFile(
f"{destinationdir}/index.html",
"lk_categories",
f'{categories[category][tk_category_name]}lk_categories',
)
util_file.replaceTextInFile(f"{destinationdir}/index.html", "lk_categories", "")