vitepress 0.22.0 → 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.
@@ -30,7 +30,7 @@ export function createRouter(loadPageModule, fallbackComponent) {
30
30
  return loadPage(href);
31
31
  }
32
32
  let latestPendingPath = null;
33
- async function loadPage(href, scrollPosition = 0) {
33
+ async function loadPage(href, scrollPosition = 0, isRetry = false) {
34
34
  const targetLoc = new URL(href, fakeHost);
35
35
  const pendingPath = (latestPendingPath = targetLoc.pathname);
36
36
  try {
@@ -75,6 +75,18 @@ export function createRouter(loadPageModule, fallbackComponent) {
75
75
  if (!err.message.match(/fetch/)) {
76
76
  console.error(err);
77
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
+ }
78
90
  if (latestPendingPath === pendingPath) {
79
91
  latestPendingPath = null;
80
92
  route.path = pendingPath;
@@ -52,7 +52,7 @@ export declare interface PageData {
52
52
  description: string
53
53
  headers: Header[]
54
54
  frontmatter: Record<string, any>
55
- lastUpdated: number
55
+ lastUpdated?: number
56
56
  }
57
57
 
58
58
  export declare interface Route {
@@ -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
- // locale string might be different based on end user
21
- // and will lead to potential hydration mismatch if calculated at build time
22
- datetime.value = new Date(page.value.lastUpdated).toLocaleString('en-US')
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-9874c5ac.js');
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');
@@ -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>;
@@ -290,6 +290,7 @@ export declare interface UserConfig<ThemeConfig = any> {
290
290
  themeConfig?: ThemeConfig;
291
291
  locales?: Record<string, LocaleConfig>;
292
292
  markdown?: MarkdownOptions;
293
+ lastUpdated?: boolean;
293
294
  /**
294
295
  * Options to pass on to `@vitejs/plugin-vue`
295
296
  */
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var serve = require('./serve-9874c5ac.js');
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');