Skip to content

Commit 862bd11

Browse files
committed
更新文档
1 parent 279073e commit 862bd11

11 files changed

Lines changed: 225 additions & 8 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const AlgoliaI18nData = {
2+
'zh-Hans': {
3+
askAiText: '询问 AI',
4+
clearText: '清空',
5+
openText: '打开',
6+
navigateText: '导航',
7+
placeholder: '请输入要搜索的内容',
8+
},
9+
'zh-Hant': {
10+
askAiText: '詢問 AI',
11+
clearText: '清空',
12+
openText: '打開',
13+
navigateText: '導航',
14+
placeholder: '請輸入要搜索的內容',
15+
},
16+
en: {
17+
askAiText: 'Ask AI',
18+
clearText: 'Clear',
19+
openText: 'Open',
20+
navigateText: 'Navigate',
21+
placeholder: 'Enter your search query',
22+
},
23+
}
24+
25+
function getAlgoliaCurrentLang() {
26+
return __isZhHant ? 'zh-Hant' : __isEn ? 'en' : 'zh-Hans'
27+
}
28+
29+
function getAlgoliaSearchConfig() {
30+
const lang = getAlgoliaCurrentLang()
31+
return {
32+
container: '#search-container',
33+
applicationId: 'EQO6IPTEY8',
34+
apiKey: '353d0a78521edc905d38a27d479bc2ec',
35+
indexName: 'docs',
36+
assistantId: '967fa671-8a15-46d8-83cd-095bb3e3619a',
37+
agentStudio: true,
38+
placeholder: AlgoliaI18nData[lang].placeholder,
39+
attributes: {
40+
primaryText: 'title',
41+
secondaryText: 'description',
42+
tertiaryText: 'itunesAuthor',
43+
url: 'url',
44+
image: 'imageUrl',
45+
},
46+
insights: false,
47+
}
48+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
function loadAlgoliaSearchComponent() {
2+
SiteSearchAskAI.init(getAlgoliaSearchConfig())
3+
4+
// SiteSearch uses 'modal-backdrop', SiteSearchAskAI uses 'modal-backdrop-askai'
5+
const bodyObserver = new MutationObserver((mutations) => {
6+
for (const mutation of mutations) {
7+
for (const node of mutation.addedNodes) {
8+
if (
9+
node.nodeType === Node.ELEMENT_NODE &&
10+
Array.from(node.classList).some((c) => c.startsWith('modal-backdrop'))
11+
) {
12+
localizationAlgoliaSearchModal(node)
13+
}
14+
}
15+
}
16+
})
17+
bodyObserver.observe(document.body, { childList: true })
18+
}
19+
20+
function localizationAlgoliaSearchModal(modal) {
21+
const lang = getAlgoliaCurrentLang()
22+
// English is the component default, no need to patch
23+
if (lang === 'en') return
24+
25+
const i18n = AlgoliaI18nData[lang]
26+
27+
const observer = new MutationObserver((mutations, obs) => {
28+
// "Clear" button
29+
const clearBtn = modal.querySelector('.ss-search-clear-button')
30+
if (clearBtn && clearBtn.textContent.trim() === 'Clear') {
31+
clearBtn.textContent = i18n.clearText
32+
}
33+
34+
// Footer kbd groups: first span = "Open", second span = "Navigate"
35+
const kbdGroups = modal.querySelectorAll('.ss-footer-kbd-group')
36+
kbdGroups.forEach((group) => {
37+
const span = group.querySelector('span')
38+
if (!span) return
39+
if (span.textContent.trim() === 'Open') {
40+
span.textContent = i18n.openText
41+
} else if (span.textContent.trim() === 'Navigate') {
42+
span.textContent = i18n.navigateText
43+
}
44+
})
45+
46+
// "Ask AI" entry in hits list: <article class="ss-ask-ai-btn">
47+
const askAiArticle = modal.querySelector('.ss-ask-ai-btn')
48+
if (askAiArticle) {
49+
const titleP = askAiArticle.querySelector('.ss-infinite-hits-item-title')
50+
if (titleP) {
51+
const firstText = titleP.childNodes[0]
52+
if (firstText && firstText.nodeType === Node.TEXT_NODE && firstText.textContent.startsWith('Ask AI')) {
53+
firstText.textContent = i18n.askAiText + ': '
54+
}
55+
}
56+
if (askAiArticle.getAttribute('aria-label') === 'Ask AI') {
57+
askAiArticle.setAttribute('aria-label', i18n.askAiText)
58+
}
59+
if (askAiArticle.getAttribute('title') === 'Ask AI') {
60+
askAiArticle.setAttribute('title', i18n.askAiText)
61+
}
62+
}
63+
})
64+
65+
observer.observe(modal, { childList: true, subtree: true })
66+
// Disconnect after the modal content has fully rendered
67+
setTimeout(() => observer.disconnect(), 2000)
68+
}

docs/assets/js/component.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// 使用 mkdocs-material 与第三方 JavaScript 库集成的方法
22
document$.subscribe(function () {
33
ComponentSystem.reinitializeAll()
4+
// Algolia 搜索
5+
loadAlgoliaSearchComponent()
46
})

docs/mirrors/index.en.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ search:
251251
<button class="md-button" title="https://tool.chinaz.com" onclick="window.open('https://tool.chinaz.com')">Domain Lookup</button>
252252
<button class="md-button" title="https://tools.ipip.net/newping.php" onclick="window.open('https://tools.ipip.net/newping.php')">Ping Latency Test</button>
253253
<button class="md-button" title="https://tools.ipip.net/traceroute.php" onclick="window.open('https://tools.ipip.net/traceroute.php')">Tracert Route Trace Test</button>
254-
<button class="md-button" title="https://ipw.cn/ipv6webcheck" onclick="window.open('https://ipw.cn/ipv6webcheck')">IPv6 Access Test</button>
254+
<button class="md-button" title="https://www.guokeyun.com/ipv6Monitor.html" onclick="window.open('https://www.guokeyun.com/ipv6Monitor.html')">IPv6 Access Test</button>
255255

256256
!!! tip "This page displays only the default repository addresses provided by the script. If you can't find the one you want, don't worry—the script supports custom addresses via command options. See [Advanced Usage](../use/index.md#command-options-advanced-usage) for details."
257257

docs/mirrors/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ search:
253253
<button class="md-button" title="https://tool.chinaz.com" onclick="window.open('https://tool.chinaz.com')">域名查询</button>
254254
<button class="md-button" title="https://tools.ipip.net/newping.php" onclick="window.open('https://tools.ipip.net/newping.php')">Ping 延迟测试</button>
255255
<button class="md-button" title="https://tools.ipip.net/traceroute.php" onclick="window.open('https://tools.ipip.net/traceroute.php')">Tracert 路由追踪测试</button>
256-
<button class="md-button" title="https://ipw.cn/ipv6webcheck" onclick="window.open('https://ipw.cn/ipv6webcheck')">IPv6 接入测试</button>
256+
<button class="md-button" title="https://www.guokeyun.com/ipv6Monitor.html" onclick="window.open('https://www.guokeyun.com/ipv6Monitor.html')">IPv6 接入测试</button>
257257

258258
!!! tip "该页面展示的均为脚本默认提供可供选择的软件源地址,如果没有找到你想使用的也没有关系,脚本支持命令选项可自定义使用,详见[高级用法](../use/index.md#命令选项高级用法)"
259259

docs/mirrors/index.zh-Hant.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ search:
253253
<button class="md-button" title="https://tool.chinaz.com" onclick="window.open('https://tool.chinaz.com')">域名查詢</button>
254254
<button class="md-button" title="https://tools.ipip.net/newping.php" onclick="window.open('https://tools.ipip.net/newping.php')">Ping 延遲測試</button>
255255
<button class="md-button" title="https://tools.ipip.net/traceroute.php" onclick="window.open('https://tools.ipip.net/traceroute.php')">Tracert 路由追蹤測試</button>
256-
<button class="md-button" title="https://ipw.cn/ipv6webcheck" onclick="window.open('https://ipw.cn/ipv6webcheck')">IPv6 接取測試</button>
256+
<button class="md-button" title="https://www.guokeyun.com/ipv6Monitor.html" onclick="window.open('https://www.guokeyun.com/ipv6Monitor.html')">IPv6 接取測試</button>
257257

258258
!!! tip "該頁面顯示的皆為腳本預設提供可供選擇的軟體源位址,如果沒有找到你想使用的也沒有關係,腳本支援命令選項可自定義使用,詳見[進階用法](../use/index.md#命令選項進階用法)"
259259

docs/sponsor/main.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@
7777
<img src="/assets/images/sponsor/yuluyundun-dark.png#only-dark" alt="语鹿云盾" />
7878
</a>
7979
<a class="sponsor-item sponsor-item-flex" target="_blank" rel="noopener noreferrer" href="https://cb2.cn" title="国内外建站快响应服务器的不二之选">
80-
<!-- 26 4 15 -->
80+
<!-- 26 5 15 -->
8181
<img src="/assets/images/sponsor/bueryun.svg" alt="不二云" />
8282
</a>
8383
<a class="sponsor-item sponsor-item-flex" target="_blank" href="https://www.runxinyun.com" title="国内挂机宝海外云服务器低至9.9元/月">
84-
<!-- 26 4 14 -->
84+
<!-- 26 7 14 -->
8585
<img src="/assets/images/sponsor/runxinyun-light.png#only-light" alt="润信云" />
8686
<img src="/assets/images/sponsor/runxinyun-dark.png#only-dark" alt="润信云" />
8787
</a>

docs/stylesheets/extra.css

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,13 @@
261261
}
262262

263263
.md-select__inner .md-select__list {
264-
padding: 6px !important;
264+
padding: 0.25rem !important;
265265
font-size: .75rem !important;
266266
border-radius: var(--component-border-radius) !important;
267267
}
268268

269269
.md-select__inner .md-select__list .md-select__item {
270-
margin: 1px;
271-
border-radius: var(--component-border-radius) !important;
270+
border-radius: calc(var(--component-border-radius) - 2px) !important;
272271
transition: background-color 0.2s;
273272
}
274273

@@ -291,6 +290,20 @@
291290
margin-left: 0 !important;
292291
}
293292

293+
.hide-button {
294+
display: none !important;
295+
}
296+
297+
@media screen and (max-width: 768px) {
298+
.hide-button {
299+
display: inline-block !important;
300+
}
301+
302+
.md-header__title {
303+
margin-left: .4rem !important;
304+
}
305+
}
306+
294307
@media screen and (min-width: 768px) {
295308
.md-header__button {
296309
border-radius: 6px;

docs/theme/partials/header.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,17 @@
6666
{% include "partials/javascripts/palette.html" %}
6767
{% endif %}
6868

69+
{% if "material/search" in config.plugins %}
70+
{% set search = config.plugins["material/search"] | attr("config") %}
71+
{% if search.enabled %}
72+
<label class="md-header__button md-icon hide-button" onclick="OpenAlgoliaSearchComponent()">
73+
{% set icon = config.theme.icon.search or "octicons/search-16" %}
74+
{% include ".icons/" ~ icon ~ ".svg" %}
75+
</label>
76+
{% include "partials/search.html" %}
77+
{% endif %}
78+
{% endif %}
79+
6980
{% if config.repo_url %}
7081
<div class="md-header__source">
7182
{% include "partials/source.html" %}

docs/theme/partials/search.html

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<div id="search-container">
2+
<div class="md-search__inner" role="search">
3+
<form class="md-search__form" name="search" onsubmit="return false;">
4+
<input type="text" class="md-search__input" name="query" aria-label="{{'AI Search' if i18n_page_locale == 'en' else 'AI 搜尋' if i18n_page_locale == 'zh-Hant' else 'AI 搜索'}}" placeholder="{{'AI Search' if i18n_page_locale == 'en' else 'AI 搜尋' if i18n_page_locale == 'zh-Hant' else 'AI 搜索'}}" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" readonly required onclick="OpenAlgoliaSearchComponent()" />
5+
<label class="md-search__icon md-icon" for="__search"> {% set icon = config.theme.icon.search or "material/magnify" %} {% include ".icons/" ~ icon ~ ".svg" %} {% set icon = config.theme.icon.previous or "material/arrow-left" %} {% include ".icons/" ~ icon ~ ".svg" %} </label>
6+
</form>
7+
<div class="md-search__output">
8+
<div class="md-search__scrollwrap" tabindex="0" data-md-scrollfix>
9+
<div class="md-search-result" data-md-component="search-result">
10+
<div class="md-search-result__meta">{{ lang.t("search.result.initializer") }}</div>
11+
<ol class="md-search-result__list" role="presentation"></ol>
12+
</div>
13+
</div>
14+
</div>
15+
</div>
16+
</div>
17+
18+
<script>
19+
const __lang = "{{ i18n_page_locale }}";
20+
let __notReadyMsg = '';
21+
switch (__lang) {
22+
case 'en':
23+
__notReadyMsg = "The search component has not yet been loaded. Please try again later.";
24+
break;
25+
case 'zh-Hant':
26+
__notReadyMsg = "搜尋元件尚未載入完畢,請稍後再試。";
27+
break;
28+
default:
29+
__notReadyMsg = "搜索组件尚未加载完毕,请稍后再试。";
30+
}
31+
32+
function OpenAlgoliaSearchComponent() {
33+
const isMac = /Mac|iPhone|iPod|iPad/i.test(navigator.platform);
34+
const dispatched = document.dispatchEvent(new KeyboardEvent('keydown', {
35+
key: 'k',
36+
code: 'KeyK',
37+
ctrlKey: !isMac,
38+
metaKey: isMac,
39+
bubbles: true,
40+
cancelable: true,
41+
}));
42+
}
43+
44+
45+
</script>
46+
47+
<style>
48+
.md-search__output {
49+
display: none !important;
50+
}
51+
.md-search__inner {
52+
padding-left: 8px;
53+
}
54+
.md-search__input {
55+
cursor: pointer !important;
56+
}
57+
.md-search__form {
58+
border-radius: 6px;
59+
}
60+
@media screen and (min-width: 60em) {
61+
.md-search-trigger {
62+
display: none;
63+
}
64+
.md-search__inner {
65+
width: 8.7rem;
66+
}
67+
}
68+
[class^="sitesearch-button"] {
69+
display: none;
70+
}
71+
</style>

0 commit comments

Comments
 (0)