2021-06-23 21:26:35 +01:00
|
|
|
### Generation helper for index.html
|
|
|
|
|
2021-06-24 00:38:47 +01:00
|
|
|
from .. import file as util_file
|
|
|
|
from .. import csv as util_csv
|
|
|
|
import shutil
|
2021-06-23 21:26:35 +01:00
|
|
|
|
2021-06-24 00:38:47 +01:00
|
|
|
|
2021-06-25 04:52:22 +01:00
|
|
|
def generate(templatedir, destinationdir, templateFilename):
|
2021-06-24 00:38:47 +01:00
|
|
|
"""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
|
2021-06-25 04:52:22 +01:00
|
|
|
filename -- the filename of the index template (always index.html)
|
2021-06-24 00:38:47 +01:00
|
|
|
"""
|
|
|
|
|
2021-06-25 04:52:22 +01:00
|
|
|
shutil.copy(f"{templatedir}/{templateFilename}", destinationdir)
|
2021-06-24 00:38:47 +01:00
|
|
|
|
2021-06-25 04:52:22 +01:00
|
|
|
idName = "tk_category_dashname"
|
|
|
|
categories = util_csv.dictReaderMultiRow("../csv/categories.csv", idName)
|
2021-06-24 00:38:47 +01:00
|
|
|
config = util_csv.dictReaderFirstRow("../csv/config.csv")
|
|
|
|
|
|
|
|
for key in config.keys():
|
2021-06-25 04:52:22 +01:00
|
|
|
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'<a class="categoryLink" href="categories/{categories[category][tk_category_dashname]}">{categories[category][tk_category_name]}</a>lk_categories',
|
|
|
|
)
|
|
|
|
util_file.replaceTextInFile(f"{destinationdir}/index.html", "lk_categories", "")
|