1
Fork 0

Fix tag navigation tree

This commit is contained in:
Jake Howard 2023-09-15 21:09:19 +01:00
parent e12e8e682b
commit 2b49b04154
Signed by: jake
GPG key ID: 57AFB45680EDD477

View file

@ -4,7 +4,7 @@ import tempfile
import os
import shutil
TAGS_TEMP_DIR = os.path.join(tempfile.gettempdir(), "tags")
TAGS_TEMP_DIR = os.path.join(tempfile.gettempdir(), "mkdocs-tags")
shutil.rmtree(TAGS_TEMP_DIR, ignore_errors=True)
os.mkdir(TAGS_TEMP_DIR)
@ -26,24 +26,26 @@ def on_files(files: Files, config):
if found_tag_page:
with open(found_tag_page.abs_src_path) as f:
content, _ = meta.get_data(f.read())
files.remove(found_tag_page)
else:
content = ""
filename = f"{tag}.md"
write_file(template.render(tag=tag, content=content).encode(), os.path.join(TAGS_TEMP_DIR, filename))
write_file(template.render(tag=tag, content=content).encode(), os.path.join(TAGS_TEMP_DIR, "tags", filename))
files.append(File(
path=filename,
path=f"tags/{filename}",
src_dir=TAGS_TEMP_DIR,
dest_dir=os.path.join(config["site_dir"], "tags"),
dest_dir=config["site_dir"],
use_directory_urls=True
))
write_file(list_template.render().encode(), os.path.join(TAGS_TEMP_DIR, "tags.md"))
write_file(list_template.render().encode(), os.path.join(TAGS_TEMP_DIR, "tags", "index.md"))
files.append(File(
path="tags.md",
path="tags/index.md",
src_dir=TAGS_TEMP_DIR,
dest_dir=config["site_dir"],
use_directory_urls=True