This is an automated email from the ASF dual-hosted git repository.

critas pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iotdb-docs.git


The following commit(s) were added to refs/heads/main by this push:
     new e295958a fix version (#446)
e295958a is described below

commit e295958a7db0c0bf117be32190dc053598c4c6a1
Author: CritasWang <[email protected]>
AuthorDate: Tue Dec 3 11:06:12 2024 +0800

    fix version (#446)
    
    * fix version
    
    * add license header
---
 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                     | 41 ++++++++++++++++++++++
 5 files changed, 54 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..73126cc8
--- /dev/null
+++ b/src/.vuepress/utils/version.ts
@@ -0,0 +1,41 @@
+/*
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+ */
+
+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 };

Reply via email to