move opener config to startup hook
This commit is contained in:
parent
a6900908b0
commit
c826bda91b
1 changed files with 12 additions and 6 deletions
|
@ -3,7 +3,7 @@ import zlib
|
||||||
from mkdocs.utils.cache import download_and_cache_url
|
from mkdocs.utils.cache import download_and_cache_url
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from mkdocs.plugins import get_plugin_logger
|
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
|
import hashlib
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from mkdocs.utils import write_file
|
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}' />"
|
return f"<img src='{image_url}' alt='{title}' />"
|
||||||
|
|
||||||
def on_config(config):
|
def on_config(config):
|
||||||
# Override user-agent so kroki accepts it
|
|
||||||
opener = build_opener()
|
|
||||||
opener.addheaders = [('User-Agent','mkdocs')]
|
|
||||||
install_opener(opener)
|
|
||||||
|
|
||||||
custom_fences = [
|
custom_fences = [
|
||||||
{
|
{
|
||||||
"name": diagram,
|
"name": diagram,
|
||||||
|
@ -69,3 +64,14 @@ def on_config(config):
|
||||||
"custom_fences": custom_fences
|
"custom_fences": custom_fences
|
||||||
}
|
}
|
||||||
return config
|
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')]
|
||||||
|
|
Loading…
Reference in a new issue