From a8087a25088d310753ae5de26584b1451a5899bf Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Thu, 14 Sep 2023 21:40:14 +0100 Subject: [PATCH] Write files with utils --- hooks/static.py | 3 +-- hooks/tags.py | 9 ++++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/hooks/static.py b/hooks/static.py index 7a3e47f..d035fe2 100644 --- a/hooks/static.py +++ b/hooks/static.py @@ -2,9 +2,8 @@ from jinja2_simple_tags import StandaloneTag import jinja2 from copy import deepcopy from mkdocs.structure.files import File, Files -from mkdocs.plugins import event_priority +from mkdocs.plugins import event_priority, get_plugin_logger import hashlib -from mkdocs.plugins import get_plugin_logger from concurrent.futures import ThreadPoolExecutor from pathlib import Path diff --git a/hooks/tags.py b/hooks/tags.py index 91209de..25fd343 100644 --- a/hooks/tags.py +++ b/hooks/tags.py @@ -1,4 +1,4 @@ -from mkdocs.utils import meta +from mkdocs.utils import meta, write_file from mkdocs.structure.files import File, Files import tempfile import os @@ -33,8 +33,8 @@ def on_files(files: Files, config): filename = f"{tag}.md" - with open(os.path.join(TAGS_TEMP_DIR, filename), "w") as f: - f.write(template.render(tag=tag, content=content)) + + write_file(template.render(tag=tag, content=content).encode(), os.path.join(TAGS_TEMP_DIR, filename)) files.append(File( path=filename, @@ -43,8 +43,7 @@ def on_files(files: Files, config): use_directory_urls=True )) - with open(os.path.join(TAGS_TEMP_DIR, "tags.md"), "w") as f: - f.write(list_template.render()) + write_file(list_template.render().encode(), os.path.join(TAGS_TEMP_DIR, "tags.md")) files.append(File( path="tags.md",