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