1
Fork 0

move opener config to startup hook

This commit is contained in:
Jake Howard 2023-09-17 17:53:59 +01:00
parent a6900908b0
commit c826bda91b
Signed by: jake
GPG key ID: 57AFB45680EDD477

View file

@ -3,7 +3,7 @@ import zlib
from mkdocs.utils.cache import download_and_cache_url
from datetime import timedelta
from mkdocs.plugins import get_plugin_logger
from urllib.request import build_opener, install_opener
from urllib.request import build_opener, install_opener, _opener
import hashlib
from functools import partial
from mkdocs.utils import write_file
@ -51,11 +51,6 @@ def fence_div_format(site_dir, source, language, *args, attrs, **kwargs):
return f"<img src='{image_url}' alt='{title}' />"
def on_config(config):
# Override user-agent so kroki accepts it
opener = build_opener()
opener.addheaders = [('User-Agent','mkdocs')]
install_opener(opener)
custom_fences = [
{
"name": diagram,
@ -69,3 +64,14 @@ def on_config(config):
"custom_fences": custom_fences
}
return config
def on_startup(command, dirty):
# Override user-agent so kroki accepts it
if _opener is None:
opener = build_opener()
install_opener(opener)
else:
opener = _opener
opener.addheaders = [('User-Agent','mkdocs')]