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-28 03:40:15 +01:00
|
|
|
# Copy template to appropriate directory
|
2021-06-25 04:52:22 +01:00
|
|
|
shutil.copy(f"{templatedir}/{templateFilename}", destinationdir)
|
2021-06-24 00:38:47 +01:00
|
|
|
|
2021-06-28 03:40:15 +01:00
|
|
|
# Read categories and config csv files
|
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")
|
|
|
|
|
2021-06-28 03:40:15 +01:00
|
|
|
# Replace config tk placeholders with values
|
2021-06-24 00:38:47 +01:00
|
|
|
for key in config.keys():
|
2021-06-25 04:52:22 +01:00
|
|
|
util_file.replaceTextInFile(f"{destinationdir}/index.html", key, config[key])
|
|
|
|
|
2021-06-28 03:40:15 +01:00
|
|
|
# lk_categories handler
|
2021-06-25 04:52:22 +01:00
|
|
|
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", "")
|