1
Fork 0

Simplify tempfile setup

This commit is contained in:
Jake Howard 2023-09-15 21:56:31 +01:00
parent 5f5a057c34
commit e23e44bfe9
Signed by: jake
GPG key ID: 57AFB45680EDD477
2 changed files with 11 additions and 9 deletions

View file

@ -1,15 +1,16 @@
import tempfile import tempfile
import shutil
import os import os
from pygments.formatters.html import HtmlFormatter from pygments.formatters.html import HtmlFormatter
from mkdocs.structure.files import File from mkdocs.structure.files import File
from minify_html import minify from minify_html import minify
from mkdocs.utils import write_file from mkdocs.utils import write_file, clean_directory
PYGMENTS_STYLE_DIR = tempfile.mkdtemp() PYGMENTS_STYLE_DIR = tempfile.mkdtemp()
shutil.rmtree(PYGMENTS_STYLE_DIR, ignore_errors=True) def on_post_build(config):
os.mkdir(PYGMENTS_STYLE_DIR) clean_directory(PYGMENTS_STYLE_DIR)
on_build_error = on_pre_build = on_post_build
def minify_css(styles: str) -> str: def minify_css(styles: str) -> str:
wrapped_styles = f"<style>{styles}</styles>" wrapped_styles = f"<style>{styles}</styles>"

View file

@ -1,13 +1,14 @@
from mkdocs.utils import meta, write_file from mkdocs.utils import meta, write_file, clean_directory
from mkdocs.structure.files import File, Files from mkdocs.structure.files import File, Files
import tempfile import tempfile
import os import os
import shutil
TAGS_TEMP_DIR = os.path.join(tempfile.gettempdir(), "mkdocs-tags") TAGS_TEMP_DIR = tempfile.mkdtemp()
shutil.rmtree(TAGS_TEMP_DIR, ignore_errors=True) def on_post_build(config):
os.mkdir(TAGS_TEMP_DIR) clean_directory(TAGS_TEMP_DIR)
on_build_error = on_pre_build = on_post_build
def on_files(files: Files, config): def on_files(files: Files, config):
tags = set() tags = set()