Skip to content

Instantly share code, notes, and snippets.

View kamilkrzyskow's full-sized avatar

Kamil Krzyśków kamilkrzyskow

  • Poland
  • 07:10 (UTC +02:00)
View GitHub Profile
@kamilkrzyskow
kamilkrzyskow / validate_block.py
Last active March 18, 2025 18:08
MkDocs hook to add block override validation
"""MkDocs hook to add block override validation
This hook adds a filter function to the Environment `validate_block`.
This function is a context filter, and takes the content, name, depth and saved checksum.
```jinja
{% block site_nav %}
{% set _ = super() | validate_block("site_nav", 2, "68f1518853") %}
{{ super() }}
{% endblock %}
@kamilkrzyskow
kamilkrzyskow / performance_debug.py
Last active April 3, 2025 15:50
MkDocs hook for performance debugging
"""MkDocs hook for performance debugging
The idea behind it is to provide a minimal curated performance log for a `mkdocs build` run.
Of course anyone can use a proper profiler, but the output often contains a lot of non-critical data
that the user has to first filter to get a clearer picture. This hook takes care of this and allows
to quickly see where a bottleneck is occurring. It also has a lower overhead than a proper profiler.
It creates a file in the current working directory, it can be configured easily with variables set
at the bottom of the file. There are also the timing categories included.