Skip to content

Commit e295958

Browse files
authored
fix version (#446)
* fix version * add license header
1 parent ec4d93d commit e295958

5 files changed

Lines changed: 54 additions & 29 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"@vuepress/plugin-redirect": "2.0.0-rc.39",
3030
"@vuepress/plugin-shiki": "2.0.0-rc.39",
3131
"@vueuse/core": "10.11.0",
32+
"algoliasearch": "^5.15.0",
3233
"element-plus": "2.4.3",
3334
"eslint": "8.55.0",
3435
"eslint-plugin-vue": "9.19.2",

src/.vuepress/components/PageFooter.vue

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,11 @@
2828
<script setup lang="ts">
2929
import { computed } from 'vue';
3030
import { usePageData } from 'vuepress/client';
31+
import { getDocVersion } from '../utils/version.js';
3132
3233
const pageData = usePageData();
3334
3435
const year = computed(() => new Date().getFullYear());
3536
36-
const getDocVersion = (branch = 'latest', path = '') => {
37-
if (path.indexOf('UserGuide/Master') > -1 || path.indexOf('UserGuide') === -1) {
38-
return branch;
39-
}
40-
const branchRex = /UserGuide\/V(\d+\.\d+\.x)/;
41-
if (branchRex.test(path)) {
42-
const tag = branchRex.exec(path)![1];
43-
return `rel/${tag.replace('.x', '')}`;
44-
}
45-
return branch;
46-
};
47-
4837
const docVersion = computed(() => getDocVersion('latest', pageData.value.path));
4938
</script>

src/.vuepress/components/docsearch/client/components/Docsearch.ts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable no-underscore-dangle */
22
/* eslint-disable @typescript-eslint/naming-convention */
3+
import type { SearchParamsObject } from 'algoliasearch';
34
import type { PropType } from 'vue';
45
import {
56
computed, defineComponent, h, onMounted, ref, watch,
@@ -18,6 +19,8 @@ import {
1819
preconnectToAlgolia,
1920
} from '../utils/index.js';
2021

22+
import { getDocVersion } from '../../../../utils/version.js';
23+
2124
declare const __DOCSEARCH_INJECT_STYLES__: boolean;
2225
const defaultBranch = 'latest';
2326

@@ -50,26 +53,14 @@ export const Docsearch = defineComponent({
5053
const hasInitialized = ref(false);
5154
const hasTriggered = ref(false);
5255

53-
const getDocVersion = (branch = 'latest', path = '') => {
54-
if (path.indexOf('UserGuide/Master') > -1 || path.indexOf('UserGuide') === -1) {
55-
return branch;
56-
}
57-
const branchRex = /UserGuide\/V(\d+\.\d+\.x)/;
58-
if (branchRex.test(path)) {
59-
const tag = branchRex.exec(path)![1];
60-
return `rel/${tag.replace('.x', '')}`;
61-
}
62-
return branch;
63-
};
64-
6556
const version = computed(() => getDocVersion(defaultBranch, pageData.value.path));
6657
// resolve docsearch options for current locale
6758
const options = computed(() => {
68-
const { locales = {}, ...options } = props.options;
59+
const { locales = {}, ...rest } = props.options;
6960

7061
return {
7162
...docSearchOptions.value,
72-
...options,
63+
...rest,
7364
...locales[routeLocale.value],
7465
};
7566
});
@@ -79,14 +70,17 @@ export const Docsearch = defineComponent({
7970
*/
8071
const initialize = async (): Promise<void> => {
8172
const { default: docsearch } = await import('@docsearch/js');
73+
74+
const { indexName, searchParameters } = options.value;
8275
docsearch({
8376
...docsearchShim,
8477
...options.value,
8578
container: `#${props.containerId}`,
8679
searchParameters: {
87-
...options.value.searchParameters,
80+
...searchParameters,
81+
indexName,
8882
facetFilters: getFacetFilters(
89-
options.value.searchParameters?.facetFilters,
83+
(searchParameters as SearchParamsObject | undefined)?.facetFilters,
9084
lang.value,
9185
version.value,
9286
),

src/.vuepress/components/docsearch/client/composables/useDocsearchShim.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const useDocsearchShim = (): Partial<DocSearchProps> => {
5757
navigator: {
5858
// when pressing Enter without metaKey
5959
navigate: ({ itemUrl }) => {
60-
router.push(itemUrl);
60+
router.push(itemUrl.replace(__VUEPRESS_BASE__, '/'));
6161
},
6262
},
6363

src/.vuepress/utils/version.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
*/
19+
20+
const getDocVersion = (defaultValue = 'latest', path = '') => {
21+
if (path.indexOf('UserGuide/Master') > -1 || path.indexOf('UserGuide') === -1) {
22+
return defaultValue;
23+
}
24+
/**
25+
* 路径 /zh/UserGuide/V1.3.0-2/QuickStart/QuickStart_apache.html, 匹配 V1.3.0-2
26+
* 路径 /zh/UserGuide/V1.2.x/QuickStart/QuickStart_apache.html, 匹配 V1.2.x
27+
* 路径 /zh/UserGuide/latest/QuickStart/QuickStart_apache.html, 匹配 latest
28+
*
29+
* 匹配路径中的版本号,UserGuide 后面的版本号为当前文档的版本号, 版本号不一定为数字,可能为 latest或其它,因此只用 / 作为分隔符
30+
*/
31+
// eslint-disable-next-line no-useless-escape
32+
const versionRex = /UserGuide\/([^\/]+)/;
33+
34+
if (versionRex.test(path)) {
35+
const tag = versionRex.exec(path)![1];
36+
return tag;
37+
}
38+
return defaultValue;
39+
};
40+
41+
export { getDocVersion };

0 commit comments

Comments
 (0)