1
Fork 0

Improve error handling

This commit is contained in:
Jake Howard 2023-09-15 22:39:35 +01:00
parent c18f29bd39
commit ce7bb446d6
Signed by: jake
GPG key ID: 57AFB45680EDD477
4 changed files with 14 additions and 2 deletions

View file

@ -40,7 +40,7 @@ def on_page_content(html, page, config, files: Files):
def resize_image(files: Files, image, width):
source_file = files.get_file_from_path(image)
if source_file is None:
return None
raise ValueError(f"Unable to find file {image!r}")
resize = Resize(source_file.abs_src_path, source_file.url, width)
RESIZES.add(resize)

View file

@ -1,5 +1,8 @@
import jinja2
from mkdocs.utils.templates import url_filter
from mkdocs.plugins import get_plugin_logger
logger = get_plugin_logger("nav")
def is_list_page(page) -> bool:
if not page.parent:
@ -41,6 +44,7 @@ def get_page(context, slug):
for page in nav.pages:
if page.file.src_uri == slug:
return page
logger.warning("Unable to find page for '%s'", slug)
return None
@jinja2.pass_context

View file

@ -16,7 +16,7 @@ on_build_error = on_pre_build = on_post_build
def minify_css(styles: str) -> str:
wrapped_styles = f"<style>{styles}</styles>"
minified_styles = minify(wrapped_styles, minify_css=True, keep_comments=True)
minified_styles = minify(wrapped_styles, minify_css=True)
return minified_styles.removeprefix("<style>").removesuffix("</style>")

View file

@ -53,6 +53,10 @@ def make_static_extension(files: Files):
def render(self, filename):
file = files.get_file_from_path(filename)
if file is None:
raise ValueError(f"Unable to find static file for {filename!r}")
return f"/{file.url}"
return StaticExtension
@ -64,6 +68,10 @@ def make_sri_extension(files: Files):
def render(self, filename):
file = files.get_file_from_path(filename)
if file is None:
raise ValueError(f"Unable to find static file for {filename!r}")
with open(file.abs_src_path, "rb") as f:
digest = hashlib.file_digest(f, "sha256").hexdigest()