From e2fc52079f53d736f1e7e1914ceaaac454e1cdf8 Mon Sep 17 00:00:00 2001 From: lrh3321 Date: Fri, 10 Oct 2025 16:19:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=BA=20img=20=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20referrerpolicy=20=E5=B1=9E=E6=80=A7?= =?UTF-8?q?=EF=BC=8C=E5=A4=84=E7=90=86=E8=A3=82=E5=9B=BE=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mkdocs.py | 5 ----- mkdocs_template.yml | 1 + overrides/javascript/referrerpolicy.js | 21 +++++++++++++++++++++ 3 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 overrides/javascript/referrerpolicy.js 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; + } + } + } +});