This is an automated email from the ASF dual-hosted git repository. critas pushed a commit to branch wx_fix_version in repository https://gitbox.apache.org/repos/asf/iotdb-docs.git
commit 9a058984b5f2fb1837de34d4683b992aa333caec Author: CritasWang <[email protected]> AuthorDate: Tue Dec 3 10:56:21 2024 +0800 fix version --- package.json | 1 + src/.vuepress/components/PageFooter.vue | 13 +---------- .../docsearch/client/components/Docsearch.ts | 26 +++++++++------------- .../client/composables/useDocsearchShim.ts | 2 +- src/.vuepress/utils/version.ts | 22 ++++++++++++++++++ 5 files changed, 35 insertions(+), 29 deletions(-) diff --git a/package.json b/package.json index 445a7e5f..80964b3f 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "@vuepress/plugin-redirect": "2.0.0-rc.39", "@vuepress/plugin-shiki": "2.0.0-rc.39", "@vueuse/core": "10.11.0", + "algoliasearch": "^5.15.0", "element-plus": "2.4.3", "eslint": "8.55.0", "eslint-plugin-vue": "9.19.2", diff --git a/src/.vuepress/components/PageFooter.vue b/src/.vuepress/components/PageFooter.vue index 54b7b558..df58dbac 100644 --- a/src/.vuepress/components/PageFooter.vue +++ b/src/.vuepress/components/PageFooter.vue @@ -28,22 +28,11 @@ <script setup lang="ts"> import { computed } from 'vue'; import { usePageData } from 'vuepress/client'; +import { getDocVersion } from '../utils/version.js'; const pageData = usePageData(); const year = computed(() => new Date().getFullYear()); -const getDocVersion = (branch = 'latest', path = '') => { - if (path.indexOf('UserGuide/Master') > -1 || path.indexOf('UserGuide') === -1) { - return branch; - } - const branchRex = /UserGuide\/V(\d+\.\d+\.x)/; - if (branchRex.test(path)) { - const tag = branchRex.exec(path)![1]; - return `rel/${tag.replace('.x', '')}`; - } - return branch; -}; - const docVersion = computed(() => getDocVersion('latest', pageData.value.path)); </script> diff --git a/src/.vuepress/components/docsearch/client/components/Docsearch.ts b/src/.vuepress/components/docsearch/client/components/Docsearch.ts index e02b4fa2..86936a2d 100644 --- a/src/.vuepress/components/docsearch/client/components/Docsearch.ts +++ b/src/.vuepress/components/docsearch/client/components/Docsearch.ts @@ -1,5 +1,6 @@ /* eslint-disable no-underscore-dangle */ /* eslint-disable @typescript-eslint/naming-convention */ +import type { SearchParamsObject } from 'algoliasearch'; import type { PropType } from 'vue'; import { computed, defineComponent, h, onMounted, ref, watch, @@ -18,6 +19,8 @@ import { preconnectToAlgolia, } from '../utils/index.js'; +import { getDocVersion } from '../../../../utils/version.js'; + declare const __DOCSEARCH_INJECT_STYLES__: boolean; const defaultBranch = 'latest'; @@ -50,26 +53,14 @@ export const Docsearch = defineComponent({ const hasInitialized = ref(false); const hasTriggered = ref(false); - const getDocVersion = (branch = 'latest', path = '') => { - if (path.indexOf('UserGuide/Master') > -1 || path.indexOf('UserGuide') === -1) { - return branch; - } - const branchRex = /UserGuide\/V(\d+\.\d+\.x)/; - if (branchRex.test(path)) { - const tag = branchRex.exec(path)![1]; - return `rel/${tag.replace('.x', '')}`; - } - return branch; - }; - const version = computed(() => getDocVersion(defaultBranch, pageData.value.path)); // resolve docsearch options for current locale const options = computed(() => { - const { locales = {}, ...options } = props.options; + const { locales = {}, ...rest } = props.options; return { ...docSearchOptions.value, - ...options, + ...rest, ...locales[routeLocale.value], }; }); @@ -79,14 +70,17 @@ export const Docsearch = defineComponent({ */ const initialize = async (): Promise<void> => { const { default: docsearch } = await import('@docsearch/js'); + + const { indexName, searchParameters } = options.value; docsearch({ ...docsearchShim, ...options.value, container: `#${props.containerId}`, searchParameters: { - ...options.value.searchParameters, + ...searchParameters, + indexName, facetFilters: getFacetFilters( - options.value.searchParameters?.facetFilters, + (searchParameters as SearchParamsObject | undefined)?.facetFilters, lang.value, version.value, ), diff --git a/src/.vuepress/components/docsearch/client/composables/useDocsearchShim.ts b/src/.vuepress/components/docsearch/client/composables/useDocsearchShim.ts index a8f33b03..d4c4c687 100644 --- a/src/.vuepress/components/docsearch/client/composables/useDocsearchShim.ts +++ b/src/.vuepress/components/docsearch/client/composables/useDocsearchShim.ts @@ -57,7 +57,7 @@ export const useDocsearchShim = (): Partial<DocSearchProps> => { navigator: { // when pressing Enter without metaKey navigate: ({ itemUrl }) => { - router.push(itemUrl); + router.push(itemUrl.replace(__VUEPRESS_BASE__, '/')); }, }, diff --git a/src/.vuepress/utils/version.ts b/src/.vuepress/utils/version.ts new file mode 100644 index 00000000..69f33be3 --- /dev/null +++ b/src/.vuepress/utils/version.ts @@ -0,0 +1,22 @@ +const getDocVersion = (defaultValue = 'latest', path = '') => { + if (path.indexOf('UserGuide/Master') > -1 || path.indexOf('UserGuide') === -1) { + return defaultValue; + } + /** + * 路径 /zh/UserGuide/V1.3.0-2/QuickStart/QuickStart_apache.html, 匹配 V1.3.0-2 + * 路径 /zh/UserGuide/V1.2.x/QuickStart/QuickStart_apache.html, 匹配 V1.2.x + * 路径 /zh/UserGuide/latest/QuickStart/QuickStart_apache.html, 匹配 latest + * + * 匹配路径中的版本号,UserGuide 后面的版本号为当前文档的版本号, 版本号不一定为数字,可能为 latest或其它,因此只用 / 作为分隔符 + */ + // eslint-disable-next-line no-useless-escape + const versionRex = /UserGuide\/([^\/]+)/; + + if (versionRex.test(path)) { + const tag = versionRex.exec(path)![1]; + return tag; + } + return defaultValue; +}; + +export { getDocVersion };
