Skip to content

Commit

Permalink
fix version (#446)
Browse files Browse the repository at this point in the history
* fix version

* add license header
  • Loading branch information
CritasWang authored Dec 3, 2024
1 parent ec4d93d commit e295958
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 29 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 1 addition & 12 deletions src/.vuepress/components/PageFooter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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>
26 changes: 10 additions & 16 deletions src/.vuepress/components/docsearch/client/components/Docsearch.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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';

Expand Down Expand Up @@ -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],
};
});
Expand All @@ -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,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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__, '/'));
},
},

Expand Down
41 changes: 41 additions & 0 deletions src/.vuepress/utils/version.ts
Original file line number Diff line number Diff line change
@@ -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 };

0 comments on commit e295958

Please sign in to comment.