diff --git a/docs/assets/js/algolia-search/config.js b/docs/assets/js/algolia-search/config.js new file mode 100644 index 0000000..9a9e7c1 --- /dev/null +++ b/docs/assets/js/algolia-search/config.js @@ -0,0 +1,48 @@ +const AlgoliaI18nData = { + 'zh-Hans': { + askAiText: '询问 AI', + clearText: '清空', + openText: '打开', + navigateText: '导航', + placeholder: '请输入要搜索的内容', + }, + 'zh-Hant': { + askAiText: '詢問 AI', + clearText: '清空', + openText: '打開', + navigateText: '導航', + placeholder: '請輸入要搜索的內容', + }, + en: { + askAiText: 'Ask AI', + clearText: 'Clear', + openText: 'Open', + navigateText: 'Navigate', + placeholder: 'Enter your search query', + }, +} + +function getAlgoliaCurrentLang() { + return __isZhHant ? 'zh-Hant' : __isEn ? 'en' : 'zh-Hans' +} + +function getAlgoliaSearchConfig() { + const lang = getAlgoliaCurrentLang() + return { + container: '#search-container', + applicationId: 'EQO6IPTEY8', + apiKey: '353d0a78521edc905d38a27d479bc2ec', + indexName: 'docs', + assistantId: '967fa671-8a15-46d8-83cd-095bb3e3619a', + agentStudio: true, + placeholder: AlgoliaI18nData[lang].placeholder, + attributes: { + primaryText: 'title', + secondaryText: 'description', + tertiaryText: 'itunesAuthor', + url: 'url', + image: 'imageUrl', + }, + insights: false, + } +} diff --git a/docs/assets/js/algolia-search/index.js b/docs/assets/js/algolia-search/index.js new file mode 100644 index 0000000..b18604b --- /dev/null +++ b/docs/assets/js/algolia-search/index.js @@ -0,0 +1,68 @@ +function loadAlgoliaSearchComponent() { + SiteSearchAskAI.init(getAlgoliaSearchConfig()) + + // SiteSearch uses 'modal-backdrop', SiteSearchAskAI uses 'modal-backdrop-askai' + const bodyObserver = new MutationObserver((mutations) => { + for (const mutation of mutations) { + for (const node of mutation.addedNodes) { + if ( + node.nodeType === Node.ELEMENT_NODE && + Array.from(node.classList).some((c) => c.startsWith('modal-backdrop')) + ) { + localizationAlgoliaSearchModal(node) + } + } + } + }) + bodyObserver.observe(document.body, { childList: true }) +} + +function localizationAlgoliaSearchModal(modal) { + const lang = getAlgoliaCurrentLang() + // English is the component default, no need to patch + if (lang === 'en') return + + const i18n = AlgoliaI18nData[lang] + + const observer = new MutationObserver((mutations, obs) => { + // "Clear" button + const clearBtn = modal.querySelector('.ss-search-clear-button') + if (clearBtn && clearBtn.textContent.trim() === 'Clear') { + clearBtn.textContent = i18n.clearText + } + + // Footer kbd groups: first span = "Open", second span = "Navigate" + const kbdGroups = modal.querySelectorAll('.ss-footer-kbd-group') + kbdGroups.forEach((group) => { + const span = group.querySelector('span') + if (!span) return + if (span.textContent.trim() === 'Open') { + span.textContent = i18n.openText + } else if (span.textContent.trim() === 'Navigate') { + span.textContent = i18n.navigateText + } + }) + + // "Ask AI" entry in hits list:
+ const askAiArticle = modal.querySelector('.ss-ask-ai-btn') + if (askAiArticle) { + const titleP = askAiArticle.querySelector('.ss-infinite-hits-item-title') + if (titleP) { + const firstText = titleP.childNodes[0] + if (firstText && firstText.nodeType === Node.TEXT_NODE && firstText.textContent.startsWith('Ask AI')) { + firstText.textContent = i18n.askAiText + ': ' + } + } + if (askAiArticle.getAttribute('aria-label') === 'Ask AI') { + askAiArticle.setAttribute('aria-label', i18n.askAiText) + } + if (askAiArticle.getAttribute('title') === 'Ask AI') { + askAiArticle.setAttribute('title', i18n.askAiText) + } + } + }) + + observer.observe(modal, { childList: true, subtree: true }) + // Disconnect after the modal content has fully rendered + setTimeout(() => observer.disconnect(), 2000) +} diff --git a/docs/assets/js/component.js b/docs/assets/js/component.js index 3c56381..bc80f0f 100644 --- a/docs/assets/js/component.js +++ b/docs/assets/js/component.js @@ -1,4 +1,6 @@ // 使用 mkdocs-material 与第三方 JavaScript 库集成的方法 document$.subscribe(function () { ComponentSystem.reinitializeAll() + // Algolia 搜索 + loadAlgoliaSearchComponent() }) diff --git a/docs/mirrors/index.en.md b/docs/mirrors/index.en.md index d95bd6a..09085db 100644 --- a/docs/mirrors/index.en.md +++ b/docs/mirrors/index.en.md @@ -251,7 +251,7 @@ search: - + !!! 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." diff --git a/docs/mirrors/index.md b/docs/mirrors/index.md index 79c1a51..7814c7f 100644 --- a/docs/mirrors/index.md +++ b/docs/mirrors/index.md @@ -253,7 +253,7 @@ search: - + !!! tip "该页面展示的均为脚本默认提供可供选择的软件源地址,如果没有找到你想使用的也没有关系,脚本支持命令选项可自定义使用,详见[高级用法](../use/index.md#命令选项高级用法)" diff --git a/docs/mirrors/index.zh-Hant.md b/docs/mirrors/index.zh-Hant.md index 5e93cc1..ff7731d 100644 --- a/docs/mirrors/index.zh-Hant.md +++ b/docs/mirrors/index.zh-Hant.md @@ -253,7 +253,7 @@ search: - + !!! tip "該頁面顯示的皆為腳本預設提供可供選擇的軟體源位址,如果沒有找到你想使用的也沒有關係,腳本支援命令選項可自定義使用,詳見[進階用法](../use/index.md#命令選項進階用法)" diff --git a/docs/sponsor/main.html b/docs/sponsor/main.html index 07d3ad1..245993e 100644 --- a/docs/sponsor/main.html +++ b/docs/sponsor/main.html @@ -77,11 +77,11 @@ 语鹿云盾 diff --git a/docs/stylesheets/extra.css b/docs/stylesheets/extra.css index 189470d..12d3200 100644 --- a/docs/stylesheets/extra.css +++ b/docs/stylesheets/extra.css @@ -261,14 +261,13 @@ } .md-select__inner .md-select__list { - padding: 6px !important; + padding: 0.25rem !important; font-size: .75rem !important; border-radius: var(--component-border-radius) !important; } .md-select__inner .md-select__list .md-select__item { - margin: 1px; - border-radius: var(--component-border-radius) !important; + border-radius: calc(var(--component-border-radius) - 2px) !important; transition: background-color 0.2s; } @@ -291,6 +290,20 @@ margin-left: 0 !important; } +.hide-button { + display: none !important; +} + +@media screen and (max-width: 768px) { + .hide-button { + display: inline-block !important; + } + + .md-header__title { + margin-left: .4rem !important; + } +} + @media screen and (min-width: 768px) { .md-header__button { border-radius: 6px; diff --git a/docs/theme/partials/header.html b/docs/theme/partials/header.html index 185f40f..9dc9023 100644 --- a/docs/theme/partials/header.html +++ b/docs/theme/partials/header.html @@ -66,6 +66,17 @@ {% include "partials/javascripts/palette.html" %} {% endif %} + {% if "material/search" in config.plugins %} + {% set search = config.plugins["material/search"] | attr("config") %} + {% if search.enabled %} + + {% include "partials/search.html" %} + {% endif %} + {% endif %} + {% if config.repo_url %}
{% include "partials/source.html" %} diff --git a/docs/theme/partials/search.html b/docs/theme/partials/search.html new file mode 100644 index 0000000..d3362fc --- /dev/null +++ b/docs/theme/partials/search.html @@ -0,0 +1,71 @@ +
+ +
+ + + + \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index cab5872..ecb9208 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -16,14 +16,18 @@ nav: extra_javascript: - https://unpkg.com/vue/dist/vue.global.prod.js - https://unpkg.com/tdesign-vue-next/dist/tdesign.min.js + - https://unpkg.com/@algolia/sitesearch@latest/dist/search-askai.min.js - assets/js/modules/tdesign-theme.js - assets/js/useThemeTransition.js - assets/js/common.js + - assets/js/algolia-search/config.js + - assets/js/algolia-search/index.js - assets/js/component.js - assets/js/components/mirrors-table/data.js - assets/js/components/mirrors-table/index.js extra_css: - https://unpkg.com/tdesign-vue-next/dist/tdesign.min.css + - https://unpkg.com/@algolia/sitesearch@latest/dist/search-askai.min.css - stylesheets/extra.css theme: