1
Fork 0

Allow custom content for tag list page

This commit is contained in:
Jake Howard 2023-09-15 22:05:07 +01:00
parent e23e44bfe9
commit 76fa263379
Signed by: jake
GPG key ID: 57AFB45680EDD477
2 changed files with 14 additions and 8 deletions

View file

@ -22,9 +22,7 @@ def on_files(files: Files, config):
tags.update(metadata.get("tags", [])) tags.update(metadata.get("tags", []))
for tag in tags: for tag in tags:
found_tag_page = files.get_file_from_path(f"tags/{tag}.md") if found_tag_page := files.get_file_from_path(f"tags/{tag}.md"):
if found_tag_page:
with open(found_tag_page.abs_src_path) as f: with open(found_tag_page.abs_src_path) as f:
content, _ = meta.get_data(f.read()) content, _ = meta.get_data(f.read())
@ -32,18 +30,26 @@ def on_files(files: Files, config):
else: else:
content = "" content = ""
filename = f"{tag}.md" filename = f"tags/{tag}.md"
write_file(template.render(tag=tag, content=content).encode(), os.path.join(TAGS_TEMP_DIR, "tags", filename)) write_file(template.render(tag=tag, content=content).encode(), os.path.join(TAGS_TEMP_DIR, filename))
files.append(File( files.append(File(
path=f"tags/{filename}", path=filename,
src_dir=TAGS_TEMP_DIR, src_dir=TAGS_TEMP_DIR,
dest_dir=config["site_dir"], dest_dir=config["site_dir"],
use_directory_urls=True use_directory_urls=True
)) ))
write_file(list_template.render().encode(), os.path.join(TAGS_TEMP_DIR, "tags", "index.md")) if found_index_page := files.get_file_from_path("tags/index.md"):
with open(found_index_page.abs_src_path) as f:
content, _ = meta.get_data(f.read())
files.remove(found_index_page)
else:
content = ""
write_file(list_template.render(content=content).encode(), os.path.join(TAGS_TEMP_DIR, "tags", "index.md"))
files.append(File( files.append(File(
path="tags/index.md", path="tags/index.md",

View file

@ -3,4 +3,4 @@ template: tag.html
title: All tags title: All tags
--- ---
All the tags {{ content }}