diff --git a/mkdocs.py b/mkdocs.py index bc8ec90f1b..9fc9e9e741 100644 --- a/mkdocs.py +++ b/mkdocs.py @@ -13,11 +13,6 @@ def _main(): ] proxy_url = "http://127.0.0.1:8091/proxy?url={url}" proxy_urls = [ - "https://static001.geekbang.org/resource/image", - "https://static001.geekbang.org/resource/avatar", - "https://static001-test.geekbang.org/resource/image", - "https://static001.infoq.cn/resource/image", - "https://static001.geekbang.org/con", ] all = [] docs_dir = Path(__file__).parent.joinpath('dist') diff --git a/mkdocs_template.yml b/mkdocs_template.yml index d5815881b7..16a600a832 100644 --- a/mkdocs_template.yml +++ b/mkdocs_template.yml @@ -68,6 +68,7 @@ extra_css: extra_javascript: - javascript/extra.js - javascript/giscus.js + - javascript/referrerpolicy.js markdown_extensions: - admonition diff --git a/overrides/javascript/referrerpolicy.js b/overrides/javascript/referrerpolicy.js new file mode 100644 index 0000000000..15bf38cc98 --- /dev/null +++ b/overrides/javascript/referrerpolicy.js @@ -0,0 +1,21 @@ +const policy = 'no-referrer'; +const noRefererPrefixes = [ + 'https://static001.geekbang.org/resource/image', + 'https://static001.geekbang.org/resource/avatar', + 'https://static001-test.geekbang.org/resource/image', + 'https://static001.infoq.cn/resource/image', + 'https://static001.geekbang.org/con' +]; + +document.querySelectorAll('p>img[src]').forEach((img) => { + const src = img.getAttribute('src'); + if (src) { + for (let index = 0; index < noRefererPrefixes.length; index++) { + const prefix = noRefererPrefixes[index]; + if (src.startsWith(prefix)) { + img.setAttribute('referrerpolicy', policy); + return; + } + } + } +});