Simplify tempfile setup
This commit is contained in:
parent
5f5a057c34
commit
e23e44bfe9
2 changed files with 11 additions and 9 deletions
|
@ -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>"
|
||||||
|
|
|
@ -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()
|
||||||
|
|
Loading…
Reference in a new issue