Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions mkdocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
1 change: 1 addition & 0 deletions mkdocs_template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ extra_css:
extra_javascript:
- javascript/extra.js
- javascript/giscus.js
- javascript/referrerpolicy.js

markdown_extensions:
- admonition
Expand Down
21 changes: 21 additions & 0 deletions overrides/javascript/referrerpolicy.js
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
});