Skip to content

Commit

Permalink
fix: 修改跳转逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
zerolee1231 committed Dec 14, 2023
1 parent 40b2b00 commit 45960f3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const branchInfo = await simpleGit('.', {}).pull().branch({});

const { current, branches } = branchInfo;
const isMain = current === 'main';
const base = isMain ? '/' : `/${current}/`;
const base = isMain ? '/main/' : `/${current}/`;
const domain = 'https://docs.deepwisdom.ai';
const versions = Object.keys(branches)
.reduce((vs, branchname) => {
Expand All @@ -66,7 +66,7 @@ const getVersions = () => {
items: [
{
text: 'main (unstable)',
link: `${domain}`,
link: `${domain}/main/`,
target: '_blank',
disabled: true,
},
Expand Down
32 changes: 29 additions & 3 deletions .vitepress/theme/Layout.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<script setup lang="ts">
import { useEventListener } from '@vueuse/core';
import { useData } from 'vitepress';
import { useData, useRoute, useRouter, withBase } from 'vitepress';
import DefaultTheme from 'vitepress/theme';
import { nextTick, provide } from 'vue';
const { isDark } = useData();
const { isDark, theme, site } = useData();
const enableTransitions = () =>
'startViewTransition' in document &&
Expand Down Expand Up @@ -50,11 +50,37 @@ useEventListener('click', (event) => {
) {
event.preventDefault();
const link = `${target.href}${location.pathname
.replace(/^\/v[^\/]*\//, '/')
.replace(site.value.base, '/')
.slice(1)}`;
window.open(link, target.target);
}
});
const router = useRouter();
const route = useRoute();
onMounted(() => {
if (!import.meta.env.DEV) {
if (location.pathname === '/') {
try {
const navlist = site.value.themeConfig.nav;
const stableVersion = navlist[navlist.length - 1].items.find((_: any) =>
_.text.includes('(stable)')
);
location.href = stableVersion.link;
return;
} catch {}
}
}
const baseWithoutLastSlash = site.value.base.replace(/\/$/, '');
if (location.pathname.replace(/\/$/, '') === baseWithoutLastSlash) {
router.go(withBase('/en/'));
}
});
</script>

<template>
Expand Down
13 changes: 9 additions & 4 deletions src/components/BlogList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
dark:border="0 solid #444 b"
>
<div w216px h144px flex-shrink-0 class="font-family: PingFang SC;">
<img :src="Article.banner" object-cover alt="" class="h100% w100%" />
<img
:src="withBase(Article.banner)"
object-cover
alt=""
class="h100% w100%"
/>
</div>
<div flex="~ col gap" flex-grow-1>
<div flex-grow-1>
Expand Down Expand Up @@ -59,7 +64,7 @@
</template>
<script setup lang="ts">
import { formateDate } from '@/utils/tool';
import { useRouter, useData } from 'vitepress';
import { useRouter, useData, withBase } from 'vitepress';
type Article = {
title: string;
description: string;
Expand Down Expand Up @@ -87,8 +92,8 @@ const go = (url: string) => {
if (url.startsWith('http')) {
window.open(url, '_blank');
} else {
const prefix = lang.value === 'en' ? '' : `/${lang.value}`;
router.go(`${prefix}${url}`);
const prefix = `/${lang.value}`;
router.go(withBase(`${prefix}${url}`));
}
};
</script>
Expand Down

0 comments on commit 45960f3

Please sign in to comment.