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.
|
|
|
|
|
2021-06-25 21:13:36 +01:00
|
|
|
templatedir -- the relative path of the template html file's directory\n
|
|
|
|
destinationpath -- the directory where index.html should be generated\n
|
|
|
|
templateFilename -- the filename of the index template (always index.html)\n
|
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"
|
2021-06-25 21:13:36 +01:00
|
|
|
|
2021-06-26 04:05:19 +01:00
|
|
|
## lk_categories handler ##
|
|
|
|
|
2021-06-25 04:52:22 +01:00
|
|
|
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',
|
|
|
|
)
|
2021-06-26 04:05:19 +01:00
|
|
|
|
2021-06-25 04:52:22 +01:00
|
|
|
util_file.replaceTextInFile(f"{destinationdir}/index.html", "lk_categories", "")
|
2021-06-26 04:05:19 +01:00
|
|
|
|
|
|
|
## End of: lk_categories handler ##
|