simple extra pages

This commit is contained in:
Guy Godfroy 2020-12-08 16:43:56 +01:00
parent 6f52b678b7
commit 95d11ef112
2 changed files with 36 additions and 16 deletions

View File

@ -90,6 +90,7 @@ post_props = [
# * index_tpl (facultative): template of the property values index
#
# Filenames are relative to meta_dir and extensions are automatically added.
# If filename contains an extension, it will override gmi_extension value.
# When a string value is facultative, it defaults to property name, except for
# index_name, which disables property values global index if not specified.
index_props = [
@ -110,3 +111,22 @@ index_props = [
"index_tpl": "authors_index"
}
]
# custom extra pages to generate
# Each entry will generate a single page.
# This is the place to define homepage and feed page for instance.
# Templates will have to handle the full unsorted list of posts.
# "name" key is mandatory. It is the filename of the page.
# If filename contains an extension, it will override gmi_extension value.
# "tpl" key is facultative, defaults to name (without extension if any)
custom_pages = [
{
"name": "index",
"tpl": "index"
},
{
"name": "atom.xml",
"tpl": "atom"
}
]

View File

@ -146,11 +146,18 @@ for dirname, subdirlist, mdlist in os.walk(md_path):
with open(gmi_subpath + "/" + gmifile, "w") as gmi:
gmi.write(gmitext)
# Generate home page
with open(tpl_path + "/index.tpl", "r") as tpl:
# Generate custom extra pages
for page_dict in custom_page:
rel_path, filename = os.path.split(page_dict["name"])
os.makedirs(rel_path, exist_ok=True)
basename, extension = os.path.spolitext(page_dict["name"])
if not extension:
extention = gmi_extension
filename = basename + extension
with open(tpm_path + "/" + page_dict.get("tpl", basename) + ".tpl", "r") as tpl:
template = Template(tpl.read())
text = template.render(posts=posts)
with open(gmi_path + "/index.gmi", "w") as gmi:
text = template.render(posts=posts)
with open(gmi_path + rel_path + "/" + filename, "w") as gmi:
gmi.write(text)
# Generate custom meta pages
@ -162,7 +169,7 @@ for prop_dict in config.index_props:
) as tpl:
template = Template(tpl.read())
text = template.render(prop=posts_prop_index[prop])
with open(gmi_path + "/" + prop_dict["index_name"] + ".gmi", "w") as gmi:
with open(gmi_path + "/" + prop_dict["index_name"] + gmi_extension, "w") as gmi:
gmi.write(text)
os.makedirs(gmi_path + "/" + prop_dict.get("item_dir", prop), exist_ok=True)
with open(tpl_path + "/" + prop_dict.get("item_tpl", prop) + ".tpl", "r") as tpl:
@ -170,13 +177,6 @@ for prop_dict in config.index_props:
for item in posts_prop_index[prop]:
text = template.render(prop_item=posts_prop_index[prop][item])
with open(
gmi_path + "/" + prop_dict.get("item_dir", prop) + "/" + item + ".gmi", "w"
gmi_path + "/" + prop_dict.get("item_dir", prop) + "/" + item + gmi_extension, "w"
) as gmi:
gmi.write(text)
# Generate posts list page
with open(tpl_path + "/posts_list.tpl", "r") as tpl:
template = Template(tpl.read())
text = template.render(posts=posts)
with open(gmi_path + "/posts.gmi", "w") as gmi:
gmi.write(text)