|
1 | 1 | <script setup lang="ts">
|
2 |
| -import { onMounted, ref } from 'vue' |
| 2 | +import { computed, onMounted, ref } from 'vue' |
3 | 3 | import { withBase } from 'vitepress'
|
4 | 4 | import { useData } from './composables/data'
|
5 | 5 | import { useLangs } from './composables/langs'
|
6 | 6 |
|
7 |
| -const { site, theme } = useData() |
| 7 | +const { site } = useData() |
8 | 8 | const { localeLinks } = useLangs({ removeCurrent: false })
|
9 | 9 |
|
10 |
| -const root = ref('/') |
| 10 | +const locale = ref({ |
| 11 | + link: '/', |
| 12 | + index: 'root' |
| 13 | +}) |
| 14 | +
|
11 | 15 | onMounted(() => {
|
12 | 16 | const path = window.location.pathname
|
13 | 17 | .replace(site.value.base, '')
|
14 | 18 | .replace(/(^.*?\/).*$/, '/$1')
|
15 | 19 | if (localeLinks.value.length) {
|
16 |
| - root.value = |
17 |
| - localeLinks.value.find(({ link }) => link.startsWith(path))?.link || |
18 |
| - localeLinks.value[0].link |
| 20 | + locale.value = |
| 21 | + localeLinks.value.find(({ link }) => link.startsWith(path)) || |
| 22 | + localeLinks.value[0] |
19 | 23 | }
|
20 | 24 | })
|
| 25 | +
|
| 26 | +const notFound = computed(() => ({ |
| 27 | + code: 404, |
| 28 | + title: 'PAGE NOT FOUND', |
| 29 | + quote: |
| 30 | + "But if you don't change your direction, and if you keep looking, you may end up where you are heading.", |
| 31 | + linkLabel: 'go to home', |
| 32 | + linkText: 'Take me home', |
| 33 | + ...(locale.value.index === 'root' |
| 34 | + ? site.value.themeConfig?.notFound |
| 35 | + : site.value.locales?.[locale.value.index]?.themeConfig?.notFound) |
| 36 | +})) |
21 | 37 | </script>
|
22 | 38 |
|
23 | 39 | <template>
|
24 | 40 | <div class="NotFound">
|
25 |
| - <p class="code">{{ theme.notFound?.code ?? '404' }}</p> |
26 |
| - <h1 class="title">{{ theme.notFound?.title ?? 'PAGE NOT FOUND' }}</h1> |
| 41 | + <p class="code">{{ notFound.code }}</p> |
| 42 | + <h1 class="title">{{ notFound.title }}</h1> |
27 | 43 | <div class="divider" />
|
28 |
| - <blockquote class="quote"> |
29 |
| - {{ |
30 |
| - theme.notFound?.quote ?? |
31 |
| - "But if you don't change your direction, and if you keep looking, you may end up where you are heading." |
32 |
| - }} |
33 |
| - </blockquote> |
| 44 | + <blockquote class="quote">{{ notFound.quote }}</blockquote> |
34 | 45 |
|
35 | 46 | <div class="action">
|
36 | 47 | <a
|
37 | 48 | class="link"
|
38 |
| - :href="withBase(root)" |
39 |
| - :aria-label="theme.notFound?.linkLabel ?? 'go to home'" |
| 49 | + :href="withBase(locale.link)" |
| 50 | + :aria-label="notFound.linkLabel" |
40 | 51 | >
|
41 |
| - {{ theme.notFound?.linkText ?? 'Take me home' }} |
| 52 | + {{ notFound.linkText }} |
42 | 53 | </a>
|
43 | 54 | </div>
|
44 | 55 | </div>
|
|
0 commit comments