Improve error handling
This commit is contained in:
parent
c18f29bd39
commit
ce7bb446d6
4 changed files with 14 additions and 2 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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>")
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in a new issue