Fix tag navigation tree
This commit is contained in:
parent
e12e8e682b
commit
2b49b04154
1 changed files with 8 additions and 6 deletions
|
@ -4,7 +4,7 @@ import tempfile
|
||||||
import os
|
import os
|
||||||
import shutil
|
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)
|
shutil.rmtree(TAGS_TEMP_DIR, ignore_errors=True)
|
||||||
os.mkdir(TAGS_TEMP_DIR)
|
os.mkdir(TAGS_TEMP_DIR)
|
||||||
|
@ -26,24 +26,26 @@ def on_files(files: Files, config):
|
||||||
if found_tag_page:
|
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())
|
||||||
|
|
||||||
|
files.remove(found_tag_page)
|
||||||
else:
|
else:
|
||||||
content = ""
|
content = ""
|
||||||
|
|
||||||
filename = f"{tag}.md"
|
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(
|
files.append(File(
|
||||||
path=filename,
|
path=f"tags/{filename}",
|
||||||
src_dir=TAGS_TEMP_DIR,
|
src_dir=TAGS_TEMP_DIR,
|
||||||
dest_dir=os.path.join(config["site_dir"], "tags"),
|
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.md"))
|
write_file(list_template.render().encode(), os.path.join(TAGS_TEMP_DIR, "tags", "index.md"))
|
||||||
|
|
||||||
files.append(File(
|
files.append(File(
|
||||||
path="tags.md",
|
path="tags/index.md",
|
||||||
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
|
||||||
|
|
Loading…
Reference in a new issue