vitepress 1.1.4 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/app/index.js +15 -2
- package/dist/client/app/router.js +7 -1
- package/dist/client/shared.js +7 -4
- package/dist/client/theme-default/NotFound.vue +13 -37
- package/dist/client/theme-default/components/VPHomeContent.vue +5 -2
- package/dist/client/theme-default/components/VPLink.vue +5 -1
- package/dist/client/theme-default/components/VPLocalSearchBox.vue +1 -5
- package/dist/client/theme-default/composables/langs.js +2 -4
- package/dist/client/theme-default/styles/vars.css +4 -4
- package/dist/node/cli.js +17 -11
- package/dist/node/index.d.ts +373 -232
- package/dist/node/index.js +11 -9
- package/dist/node/{serve-CXVdC751.js → serve-DF70M2uf.js} +235 -260
- package/package.json +32 -35
- package/types/shared.d.ts +6 -1
package/dist/client/app/index.js
CHANGED
|
@@ -108,8 +108,21 @@ function newRouter() {
|
|
|
108
108
|
if (isInitialPageLoad || initialPath === pageFilePath) {
|
|
109
109
|
pageFilePath = pageFilePath.replace(/\.js$/, '.lean.js');
|
|
110
110
|
}
|
|
111
|
-
if (import.meta.env.
|
|
112
|
-
pageModule = import(/*@vite-ignore*/ pageFilePath
|
|
111
|
+
if (import.meta.env.DEV) {
|
|
112
|
+
pageModule = import(/*@vite-ignore*/ pageFilePath).catch(() => {
|
|
113
|
+
// try with/without trailing slash
|
|
114
|
+
// in prod this is handled in src/client/app/utils.ts#pathToFile
|
|
115
|
+
const url = new URL(pageFilePath, 'http://a.com');
|
|
116
|
+
const path = (url.pathname.endsWith('/index.md')
|
|
117
|
+
? url.pathname.slice(0, -9) + '.md'
|
|
118
|
+
: url.pathname.slice(0, -3) + '/index.md') +
|
|
119
|
+
url.search +
|
|
120
|
+
url.hash;
|
|
121
|
+
return import(/*@vite-ignore*/ path);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
else if (import.meta.env.SSR) {
|
|
125
|
+
pageModule = import(/*@vite-ignore*/ `${pageFilePath}?t=${Date.now()}`);
|
|
113
126
|
}
|
|
114
127
|
else {
|
|
115
128
|
pageModule = import(/*@vite-ignore*/ pageFilePath);
|
|
@@ -102,7 +102,13 @@ export function createRouter(loadPageModule, fallbackComponent) {
|
|
|
102
102
|
latestPendingPath = null;
|
|
103
103
|
route.path = inBrowser ? pendingPath : withBase(pendingPath);
|
|
104
104
|
route.component = fallbackComponent ? markRaw(fallbackComponent) : null;
|
|
105
|
-
|
|
105
|
+
const relativePath = inBrowser
|
|
106
|
+
? pendingPath
|
|
107
|
+
.replace(/(^|\/)$/, '$1index')
|
|
108
|
+
.replace(/(\.html)?$/, '.md')
|
|
109
|
+
.replace(/^\//, '')
|
|
110
|
+
: '404.md';
|
|
111
|
+
route.data = { ...notFoundPageData, relativePath };
|
|
106
112
|
}
|
|
107
113
|
}
|
|
108
114
|
}
|
package/dist/client/shared.js
CHANGED
|
@@ -5,7 +5,7 @@ const HASH_OR_QUERY_RE = /[?#].*$/;
|
|
|
5
5
|
const INDEX_OR_EXT_RE = /(?:(^|\/)index)?\.(?:md|html)$/;
|
|
6
6
|
export const inBrowser = typeof document !== 'undefined';
|
|
7
7
|
export const notFoundPageData = {
|
|
8
|
-
relativePath: '',
|
|
8
|
+
relativePath: '404.md',
|
|
9
9
|
filePath: '',
|
|
10
10
|
title: '404',
|
|
11
11
|
description: 'Not Found',
|
|
@@ -39,13 +39,16 @@ function normalize(path) {
|
|
|
39
39
|
export function isExternal(path) {
|
|
40
40
|
return EXTERNAL_URL_RE.test(path);
|
|
41
41
|
}
|
|
42
|
+
export function getLocaleForPath(siteData, relativePath) {
|
|
43
|
+
return (Object.keys(siteData?.locales || {}).find((key) => key !== 'root' &&
|
|
44
|
+
!isExternal(key) &&
|
|
45
|
+
isActive(relativePath, `/${key}/`, true)) || 'root');
|
|
46
|
+
}
|
|
42
47
|
/**
|
|
43
48
|
* this merges the locales data to the main data by the route
|
|
44
49
|
*/
|
|
45
50
|
export function resolveSiteDataByRoute(siteData, relativePath) {
|
|
46
|
-
const localeIndex =
|
|
47
|
-
!isExternal(key) &&
|
|
48
|
-
isActive(relativePath, `/${key}/`, true)) || 'root';
|
|
51
|
+
const localeIndex = getLocaleForPath(siteData, relativePath);
|
|
49
52
|
return Object.assign({}, siteData, {
|
|
50
53
|
localeIndex,
|
|
51
54
|
lang: siteData.locales[localeIndex]?.lang ?? siteData.lang,
|
|
@@ -1,55 +1,31 @@
|
|
|
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 {
|
|
8
|
-
const {
|
|
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
|
|
42
|
-
<h1 class="title">{{ notFound
|
|
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">
|
|
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(
|
|
50
|
-
:aria-label="notFound
|
|
25
|
+
:href="withBase(currentLang.link)"
|
|
26
|
+
:aria-label="theme.notFound?.linkLabel ?? 'go to home'"
|
|
51
27
|
>
|
|
52
|
-
{{ notFound
|
|
28
|
+
{{ theme.notFound?.linkText ?? 'Take me home' }}
|
|
53
29
|
</a>
|
|
54
30
|
</div>
|
|
55
31
|
</div>
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { useWindowSize } from '@vueuse/core'
|
|
3
3
|
|
|
4
|
-
const { width: vw } = useWindowSize({
|
|
4
|
+
const { width: vw } = useWindowSize({
|
|
5
|
+
initialWidth: 0,
|
|
6
|
+
includeScrollbar: false
|
|
7
|
+
})
|
|
5
8
|
</script>
|
|
6
9
|
|
|
7
10
|
<template>
|
|
@@ -46,7 +49,7 @@ const { width: vw } = useWindowSize({ includeScrollbar: false })
|
|
|
46
49
|
}
|
|
47
50
|
|
|
48
51
|
.vp-doc :deep(.VPHomeSponsors a),
|
|
49
|
-
.vp-doc :deep(.VPTeamPage a){
|
|
52
|
+
.vp-doc :deep(.VPTeamPage a) {
|
|
50
53
|
text-decoration: none;
|
|
51
54
|
}
|
|
52
55
|
</style>
|
|
@@ -12,7 +12,11 @@ const props = defineProps<{
|
|
|
12
12
|
}>()
|
|
13
13
|
|
|
14
14
|
const tag = computed(() => props.tag ?? (props.href ? 'a' : 'span'))
|
|
15
|
-
const isExternal = computed(
|
|
15
|
+
const isExternal = computed(
|
|
16
|
+
() =>
|
|
17
|
+
(props.href && EXTERNAL_URL_RE.test(props.href)) ||
|
|
18
|
+
props.target === '_blank'
|
|
19
|
+
)
|
|
16
20
|
</script>
|
|
17
21
|
|
|
18
22
|
<template>
|
|
@@ -291,11 +291,7 @@ watch(results, (r) => {
|
|
|
291
291
|
function scrollToSelectedResult() {
|
|
292
292
|
nextTick(() => {
|
|
293
293
|
const selectedEl = document.querySelector('.result.selected')
|
|
294
|
-
|
|
295
|
-
selectedEl.scrollIntoView({
|
|
296
|
-
block: 'nearest'
|
|
297
|
-
})
|
|
298
|
-
}
|
|
294
|
+
selectedEl?.scrollIntoView({ block: 'nearest' })
|
|
299
295
|
})
|
|
300
296
|
}
|
|
301
297
|
|
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import { computed } from 'vue';
|
|
2
2
|
import { ensureStartingSlash } from '../support/utils';
|
|
3
3
|
import { useData } from './data';
|
|
4
|
-
export function useLangs({
|
|
4
|
+
export function useLangs({ correspondingLink = false } = {}) {
|
|
5
5
|
const { site, localeIndex, page, theme, hash } = useData();
|
|
6
6
|
const currentLang = computed(() => ({
|
|
7
|
-
index: localeIndex.value,
|
|
8
7
|
label: site.value.locales[localeIndex.value]?.label,
|
|
9
8
|
link: site.value.locales[localeIndex.value]?.link ||
|
|
10
9
|
(localeIndex.value === 'root' ? '/' : `/${localeIndex.value}/`)
|
|
11
10
|
}));
|
|
12
|
-
const localeLinks = computed(() => Object.entries(site.value.locales).flatMap(([key, value]) =>
|
|
11
|
+
const localeLinks = computed(() => Object.entries(site.value.locales).flatMap(([key, value]) => currentLang.value.label === value.label
|
|
13
12
|
? []
|
|
14
13
|
: {
|
|
15
|
-
index: key,
|
|
16
14
|
text: value.label,
|
|
17
15
|
link: normalizeLink(value.link || (key === 'root' ? '/' : `/${key}/`), theme.value.i18nRouting !== false && correspondingLink, page.value.relativePath.slice(currentLang.value.link.length - 1), !site.value.cleanUrls) + hash.value
|
|
18
16
|
}));
|
|
@@ -268,11 +268,11 @@
|
|
|
268
268
|
font-optical-sizing: auto;
|
|
269
269
|
}
|
|
270
270
|
|
|
271
|
-
:root:lang(zh) {
|
|
271
|
+
:root:where(:lang(zh)) {
|
|
272
272
|
--vp-font-family-base: 'Punctuation SC', 'Inter', ui-sans-serif, system-ui,
|
|
273
|
-
'PingFang SC', 'Noto Sans CJK SC', 'Noto Sans SC', 'Heiti SC',
|
|
274
|
-
'Microsoft YaHei', sans-serif, 'Apple Color Emoji',
|
|
275
|
-
'Segoe UI Symbol', 'Noto Color Emoji';
|
|
273
|
+
'PingFang SC', 'Noto Sans CJK SC', 'Noto Sans SC', 'Heiti SC',
|
|
274
|
+
'Microsoft YaHei', 'DengXian', sans-serif, 'Apple Color Emoji',
|
|
275
|
+
'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
|
|
276
276
|
}
|
|
277
277
|
|
|
278
278
|
/**
|
package/dist/node/cli.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as getDefaultExportFromCjs, q as c, t as clearCache, n as init, b as build, o as serve, v as version, p as createServer } from './serve-
|
|
1
|
+
import { a as getDefaultExportFromCjs, q as c, t as clearCache, n as init, b as build, o as serve, v as version, p as createServer } from './serve-DF70M2uf.js';
|
|
2
2
|
import { createLogger } from 'vite';
|
|
3
3
|
import 'path';
|
|
4
4
|
import 'shiki';
|
|
@@ -12,16 +12,19 @@ import 'node:fs/promises';
|
|
|
12
12
|
import 'node:url';
|
|
13
13
|
import 'node:fs';
|
|
14
14
|
import 'fs';
|
|
15
|
-
import '
|
|
16
|
-
import '
|
|
17
|
-
import '
|
|
18
|
-
import 'string_decoder';
|
|
15
|
+
import 'node:events';
|
|
16
|
+
import 'node:stream';
|
|
17
|
+
import 'node:string_decoder';
|
|
19
18
|
import 'util';
|
|
20
19
|
import 'os';
|
|
21
20
|
import 'assert';
|
|
21
|
+
import 'events';
|
|
22
|
+
import 'stream';
|
|
22
23
|
import 'readline';
|
|
23
24
|
import 'child_process';
|
|
25
|
+
import 'string_decoder';
|
|
24
26
|
import 'zlib';
|
|
27
|
+
import '@vue/shared';
|
|
25
28
|
import 'node:readline';
|
|
26
29
|
import 'node:tty';
|
|
27
30
|
import 'http';
|
|
@@ -308,8 +311,7 @@ function bindShortcuts(server, createDevServer) {
|
|
|
308
311
|
await server.close().finally(() => process.exit(1));
|
|
309
312
|
return;
|
|
310
313
|
}
|
|
311
|
-
if (actionRunning)
|
|
312
|
-
return;
|
|
314
|
+
if (actionRunning) return;
|
|
313
315
|
if (input === "h") {
|
|
314
316
|
server.config.logger.info(
|
|
315
317
|
[
|
|
@@ -322,8 +324,7 @@ function bindShortcuts(server, createDevServer) {
|
|
|
322
324
|
);
|
|
323
325
|
}
|
|
324
326
|
const shortcut = SHORTCUTS.find((shortcut2) => shortcut2.key === input);
|
|
325
|
-
if (!shortcut)
|
|
326
|
-
return;
|
|
327
|
+
if (!shortcut) return;
|
|
327
328
|
actionRunning = true;
|
|
328
329
|
await shortcut.action(server, createDevServer);
|
|
329
330
|
actionRunning = false;
|
|
@@ -420,6 +421,7 @@ if (!command || command === "dev") {
|
|
|
420
421
|
createDevServer().catch((err) => {
|
|
421
422
|
createLogger().error(
|
|
422
423
|
`${c.red(`failed to start server. error:`)}
|
|
424
|
+
${err.message}
|
|
423
425
|
${err.stack}`
|
|
424
426
|
);
|
|
425
427
|
process.exit(1);
|
|
@@ -431,14 +433,18 @@ ${err.stack}`
|
|
|
431
433
|
logVersion();
|
|
432
434
|
if (command === "build") {
|
|
433
435
|
build(root, argv).catch((err) => {
|
|
434
|
-
createLogger().error(
|
|
435
|
-
|
|
436
|
+
createLogger().error(
|
|
437
|
+
`${c.red(`build error:`)}
|
|
438
|
+
${err.message}
|
|
439
|
+
${err.stack}`
|
|
440
|
+
);
|
|
436
441
|
process.exit(1);
|
|
437
442
|
});
|
|
438
443
|
} else if (command === "serve" || command === "preview") {
|
|
439
444
|
serve(argv).catch((err) => {
|
|
440
445
|
createLogger().error(
|
|
441
446
|
`${c.red(`failed to start server. error:`)}
|
|
447
|
+
${err.message}
|
|
442
448
|
${err.stack}`
|
|
443
449
|
);
|
|
444
450
|
process.exit(1);
|