vitepress 0.21.4 → 0.22.1
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/data.js +2 -1
- package/dist/client/app/router.js +24 -2
- package/dist/client/index.d.ts +4 -2
- package/dist/client/shared.js +1 -0
- package/dist/client/theme-default/components/LastUpdated.vue +6 -4
- package/dist/client/theme-default/components/PageFooter.vue +4 -1
- package/dist/node/cli.js +2 -1
- package/dist/node/index.d.ts +8 -1
- package/dist/node/index.js +2 -1
- package/dist/node/{serve-9731a371.js → serve-c594fc71.js} +1288 -509
- package/package.json +17 -15
- package/theme.d.ts +9 -0
- package/types/shared.d.ts +2 -1
- package/dist/vitepress.d.ts +0 -311
package/dist/client/app/data.js
CHANGED
|
@@ -5,7 +5,8 @@ import { withBase } from './utils';
|
|
|
5
5
|
export const dataSymbol = Symbol();
|
|
6
6
|
export const siteDataRef = shallowRef(parse(serializedSiteData));
|
|
7
7
|
function parse(data) {
|
|
8
|
-
|
|
8
|
+
const parsed = JSON.parse(data);
|
|
9
|
+
return (import.meta.env.DEV ? readonly(parsed) : parsed);
|
|
9
10
|
}
|
|
10
11
|
// hmr
|
|
11
12
|
if (import.meta.hot) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { reactive, inject, markRaw, nextTick, readonly } from 'vue';
|
|
2
2
|
import { inBrowser } from './utils';
|
|
3
|
+
import { siteDataRef } from './data';
|
|
3
4
|
export const RouterSymbol = Symbol();
|
|
4
5
|
// we are just using URL to parse the pathname and hash - the base doesn't
|
|
5
6
|
// matter and is only passed to support same-host hrefs.
|
|
@@ -29,7 +30,7 @@ export function createRouter(loadPageModule, fallbackComponent) {
|
|
|
29
30
|
return loadPage(href);
|
|
30
31
|
}
|
|
31
32
|
let latestPendingPath = null;
|
|
32
|
-
async function loadPage(href, scrollPosition = 0) {
|
|
33
|
+
async function loadPage(href, scrollPosition = 0, isRetry = false) {
|
|
33
34
|
const targetLoc = new URL(href, fakeHost);
|
|
34
35
|
const pendingPath = (latestPendingPath = targetLoc.pathname);
|
|
35
36
|
try {
|
|
@@ -74,6 +75,18 @@ export function createRouter(loadPageModule, fallbackComponent) {
|
|
|
74
75
|
if (!err.message.match(/fetch/)) {
|
|
75
76
|
console.error(err);
|
|
76
77
|
}
|
|
78
|
+
// retry on fetch fail: the page to hash map may have been invalidated
|
|
79
|
+
// because a new deploy happened while the page is open. Try to fetch
|
|
80
|
+
// the updated pageToHash map and fetch again.
|
|
81
|
+
if (!isRetry) {
|
|
82
|
+
try {
|
|
83
|
+
const res = await fetch(siteDataRef.value.base + 'hashmap.json');
|
|
84
|
+
window.__VP_HASH_MAP__ = await res.json();
|
|
85
|
+
await loadPage(href, scrollPosition, true);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
catch (e) { }
|
|
89
|
+
}
|
|
77
90
|
if (latestPendingPath === pendingPath) {
|
|
78
91
|
latestPendingPath = null;
|
|
79
92
|
route.path = pendingPath;
|
|
@@ -148,7 +161,16 @@ function scrollTo(el, hash, smooth = false) {
|
|
|
148
161
|
console.warn(e);
|
|
149
162
|
}
|
|
150
163
|
if (target) {
|
|
151
|
-
|
|
164
|
+
let offset = siteDataRef.value.scrollOffset;
|
|
165
|
+
if (typeof offset === 'string') {
|
|
166
|
+
offset =
|
|
167
|
+
document.querySelector(offset).getBoundingClientRect().bottom + 24;
|
|
168
|
+
}
|
|
169
|
+
const targetPadding = parseInt(window.getComputedStyle(target).paddingTop, 10);
|
|
170
|
+
const targetTop = window.scrollY +
|
|
171
|
+
target.getBoundingClientRect().top -
|
|
172
|
+
offset +
|
|
173
|
+
targetPadding;
|
|
152
174
|
// only smooth scroll if distance is smaller than screen height.
|
|
153
175
|
if (!smooth || Math.abs(targetTop - window.scrollY) > window.innerHeight) {
|
|
154
176
|
window.scrollTo(0, targetTop);
|
package/dist/client/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { ComponentOptions } from 'vue';
|
|
|
6
6
|
import { ComponentOptionsMixin } from 'vue';
|
|
7
7
|
import { DefineComponent } from 'vue';
|
|
8
8
|
import { EmitsOptions } from 'vue';
|
|
9
|
+
import { ExtractPropTypes } from 'vue';
|
|
9
10
|
import { Ref } from 'vue';
|
|
10
11
|
import { RendererElement } from 'vue';
|
|
11
12
|
import { RendererNode } from 'vue';
|
|
@@ -14,7 +15,7 @@ import { VNodeProps } from 'vue';
|
|
|
14
15
|
|
|
15
16
|
export declare const Content: DefineComponent< {}, () => VNode<RendererNode, RendererElement, {
|
|
16
17
|
[key: string]: any;
|
|
17
|
-
}>, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, EmitsOptions, string, VNodeProps & AllowedComponentProps & ComponentCustomProps, Readonly<{}
|
|
18
|
+
}>, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, EmitsOptions, string, VNodeProps & AllowedComponentProps & ComponentCustomProps, Readonly<ExtractPropTypes< {}>>, {}>;
|
|
18
19
|
|
|
19
20
|
export declare const Debug: ComponentOptions<{}, any, any, any, any, any, any, any>;
|
|
20
21
|
|
|
@@ -51,7 +52,7 @@ export declare interface PageData {
|
|
|
51
52
|
description: string
|
|
52
53
|
headers: Header[]
|
|
53
54
|
frontmatter: Record<string, any>
|
|
54
|
-
lastUpdated
|
|
55
|
+
lastUpdated?: number
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
export declare interface Route {
|
|
@@ -76,6 +77,7 @@ export declare interface SiteData<ThemeConfig = any> {
|
|
|
76
77
|
description: string
|
|
77
78
|
head: HeadConfig[]
|
|
78
79
|
themeConfig: ThemeConfig
|
|
80
|
+
scrollOffset: number | string
|
|
79
81
|
locales: Record<string, LocaleConfig>
|
|
80
82
|
/**
|
|
81
83
|
* Available locales for the site when it has defined `locales` in its
|
package/dist/client/shared.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { ref, computed, onMounted } from 'vue'
|
|
2
|
+
import { ref, computed, onMounted, watchEffect } from 'vue'
|
|
3
3
|
import { useData } from 'vitepress'
|
|
4
4
|
|
|
5
5
|
const { theme, page } = useData()
|
|
@@ -17,9 +17,11 @@ const prefix = computed(() => {
|
|
|
17
17
|
|
|
18
18
|
const datetime = ref('')
|
|
19
19
|
onMounted(() => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
watchEffect(() => {
|
|
21
|
+
// locale string might be different based on end user
|
|
22
|
+
// and will lead to potential hydration mismatch if calculated at build time
|
|
23
|
+
datetime.value = new Date(page.value.lastUpdated!).toLocaleString('en-US')
|
|
24
|
+
})
|
|
23
25
|
})
|
|
24
26
|
</script>
|
|
25
27
|
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import EditLink from './EditLink.vue'
|
|
3
3
|
import LastUpdated from './LastUpdated.vue'
|
|
4
|
+
import { useData } from 'vitepress'
|
|
5
|
+
|
|
6
|
+
const { page } = useData()
|
|
4
7
|
</script>
|
|
5
8
|
|
|
6
9
|
<template>
|
|
@@ -9,7 +12,7 @@ import LastUpdated from './LastUpdated.vue'
|
|
|
9
12
|
<EditLink />
|
|
10
13
|
</div>
|
|
11
14
|
<div class="updated">
|
|
12
|
-
<LastUpdated />
|
|
15
|
+
<LastUpdated v-if="page.lastUpdated" />
|
|
13
16
|
</div>
|
|
14
17
|
</footer>
|
|
15
18
|
</template>
|
package/dist/node/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var serve = require('./serve-
|
|
3
|
+
var serve = require('./serve-c594fc71.js');
|
|
4
4
|
require('fs');
|
|
5
5
|
require('path');
|
|
6
6
|
require('url');
|
|
@@ -13,6 +13,7 @@ require('util');
|
|
|
13
13
|
require('buffer');
|
|
14
14
|
require('punycode');
|
|
15
15
|
require('prismjs');
|
|
16
|
+
require('child_process');
|
|
16
17
|
require('querystring');
|
|
17
18
|
require('tty');
|
|
18
19
|
require('net');
|
package/dist/node/index.d.ts
CHANGED
|
@@ -233,7 +233,7 @@ export declare interface ServeOptions {
|
|
|
233
233
|
port?: number;
|
|
234
234
|
}
|
|
235
235
|
|
|
236
|
-
export declare interface SiteConfig<ThemeConfig = any> extends Pick<UserConfig, 'markdown' | 'vue' | 'vite' | 'shouldPreload' | 'mpa'> {
|
|
236
|
+
export declare interface SiteConfig<ThemeConfig = any> extends Pick<UserConfig, 'markdown' | 'vue' | 'vite' | 'shouldPreload' | 'mpa' | 'lastUpdated'> {
|
|
237
237
|
root: string;
|
|
238
238
|
srcDir: string;
|
|
239
239
|
site: SiteData<ThemeConfig>;
|
|
@@ -256,6 +256,7 @@ export declare interface SiteData<ThemeConfig = any> {
|
|
|
256
256
|
description: string
|
|
257
257
|
head: HeadConfig[]
|
|
258
258
|
themeConfig: ThemeConfig
|
|
259
|
+
scrollOffset: number | string
|
|
259
260
|
locales: Record<string, LocaleConfig>
|
|
260
261
|
/**
|
|
261
262
|
* Available locales for the site when it has defined `locales` in its
|
|
@@ -289,6 +290,7 @@ export declare interface UserConfig<ThemeConfig = any> {
|
|
|
289
290
|
themeConfig?: ThemeConfig;
|
|
290
291
|
locales?: Record<string, LocaleConfig>;
|
|
291
292
|
markdown?: MarkdownOptions;
|
|
293
|
+
lastUpdated?: boolean;
|
|
292
294
|
/**
|
|
293
295
|
* Options to pass on to `@vitejs/plugin-vue`
|
|
294
296
|
*/
|
|
@@ -301,6 +303,11 @@ export declare interface UserConfig<ThemeConfig = any> {
|
|
|
301
303
|
srcExclude?: string[];
|
|
302
304
|
outDir?: string;
|
|
303
305
|
shouldPreload?: (link: string, page: string) => boolean;
|
|
306
|
+
/**
|
|
307
|
+
* Configure the scroll offset when the theme has a sticky header.
|
|
308
|
+
* Can be a number or a selector element to get the offset from.
|
|
309
|
+
*/
|
|
310
|
+
scrollOffset?: number | string;
|
|
304
311
|
/**
|
|
305
312
|
* Enable MPA / zero-JS mode
|
|
306
313
|
* @experimental
|
package/dist/node/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var serve = require('./serve-
|
|
5
|
+
var serve = require('./serve-c594fc71.js');
|
|
6
6
|
require('vite');
|
|
7
7
|
require('readline');
|
|
8
8
|
require('assert');
|
|
@@ -15,6 +15,7 @@ require('fs');
|
|
|
15
15
|
require('punycode');
|
|
16
16
|
require('prismjs');
|
|
17
17
|
require('url');
|
|
18
|
+
require('child_process');
|
|
18
19
|
require('querystring');
|
|
19
20
|
require('tty');
|
|
20
21
|
require('net');
|