vitepress 0.21.6 → 0.22.3

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/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  ---
7
7
 
8
- VitePress is [VuePress](http://vuepress.vuejs.org/)' spiritual successor, built on top of [vite](https://github.com/vuejs/vite).
8
+ VitePress is [VuePress](https://vuepress.vuejs.org)' spiritual successor, built on top of [vite](https://github.com/vitejs/vite).
9
9
 
10
10
  ## Documentation
11
11
 
@@ -13,14 +13,14 @@ To check out docs, visit [vitepress.vuejs.org](https://vitepress.vuejs.org).
13
13
 
14
14
  ## Changelog
15
15
 
16
- Detailed changes for each release are documented in the [CHANGELOG](https://github.com/vuejs/vitepress/blob/master/CHANGELOG.md).
16
+ Detailed changes for each release are documented in the [CHANGELOG](https://github.com/vuejs/vitepress/blob/main/CHANGELOG.md).
17
17
 
18
18
  ## Contribution
19
19
 
20
- Please make sure to read the [Contributing Guide](./.github/contributing.md) before making a pull request.
20
+ Please make sure to read the [Contributing Guide](https://github.com/vuejs/vitepress/blob/main/.github/contributing.md) before making a pull request.
21
21
 
22
22
  ## License
23
23
 
24
- [MIT](https://opensource.org/licenses/MIT)
24
+ [MIT](https://github.com/vuejs/vitepress/blob/main/LICENSE)
25
25
 
26
26
  Copyright (c) 2019-present, Yuxi (Evan) You
@@ -5,13 +5,18 @@ export const RouterSymbol = Symbol();
5
5
  // we are just using URL to parse the pathname and hash - the base doesn't
6
6
  // matter and is only passed to support same-host hrefs.
7
7
  const fakeHost = `http://a.com`;
8
+ const notFoundPageData = {
9
+ relativePath: '',
10
+ title: '404',
11
+ description: 'Not Found',
12
+ headers: [],
13
+ frontmatter: {},
14
+ lastUpdated: 0
15
+ };
8
16
  const getDefaultRoute = () => ({
9
17
  path: '/',
10
18
  component: null,
11
- // this will be set upon initial page load, which is before
12
- // the app is mounted, so it's guaranteed to be available in
13
- // components. We just need enough data for 404 pages to render.
14
- data: { frontmatter: {} }
19
+ data: notFoundPageData
15
20
  });
16
21
  export function createRouter(loadPageModule, fallbackComponent) {
17
22
  const route = reactive(getDefaultRoute());
@@ -30,7 +35,7 @@ export function createRouter(loadPageModule, fallbackComponent) {
30
35
  return loadPage(href);
31
36
  }
32
37
  let latestPendingPath = null;
33
- async function loadPage(href, scrollPosition = 0) {
38
+ async function loadPage(href, scrollPosition = 0, isRetry = false) {
34
39
  const targetLoc = new URL(href, fakeHost);
35
40
  const pendingPath = (latestPendingPath = targetLoc.pathname);
36
41
  try {
@@ -75,10 +80,23 @@ export function createRouter(loadPageModule, fallbackComponent) {
75
80
  if (!err.message.match(/fetch/)) {
76
81
  console.error(err);
77
82
  }
83
+ // retry on fetch fail: the page to hash map may have been invalidated
84
+ // because a new deploy happened while the page is open. Try to fetch
85
+ // the updated pageToHash map and fetch again.
86
+ if (!isRetry) {
87
+ try {
88
+ const res = await fetch(siteDataRef.value.base + 'hashmap.json');
89
+ window.__VP_HASH_MAP__ = await res.json();
90
+ await loadPage(href, scrollPosition, true);
91
+ return;
92
+ }
93
+ catch (e) { }
94
+ }
78
95
  if (latestPendingPath === pendingPath) {
79
96
  latestPendingPath = null;
80
97
  route.path = pendingPath;
81
98
  route.component = fallbackComponent ? markRaw(fallbackComponent) : null;
99
+ route.data = notFoundPageData;
82
100
  }
83
101
  }
84
102
  }
@@ -141,7 +159,7 @@ export function useRoute() {
141
159
  function scrollTo(el, hash, smooth = false) {
142
160
  let target = null;
143
161
  try {
144
- target = el.classList.contains('.header-anchor')
162
+ target = el.classList.contains('header-anchor')
145
163
  ? el
146
164
  : document.querySelector(decodeURIComponent(hash));
147
165
  }
@@ -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 {
@@ -4,12 +4,11 @@ import { useRoute, useData } from 'vitepress'
4
4
  import { isSideBarEmpty, getSideBarConfig } from './support/sideBar'
5
5
 
6
6
  // components
7
+ import Home from './components/Home.vue'
7
8
  import NavBar from './components/NavBar.vue'
8
9
  import SideBar from './components/SideBar.vue'
9
10
  import Page from './components/Page.vue'
10
11
 
11
- const Home = defineAsyncComponent(() => import('./components/Home.vue'))
12
-
13
12
  const NoopComponent = () => null
14
13
 
15
14
  const CarbonAds = __CARBON__
@@ -54,25 +54,18 @@ const { lang } = useData()
54
54
 
55
55
  // if the user has multiple locales, the search results should be filtered
56
56
  // based on the language
57
- const facetFilters: string[] = props.multilang
58
- ? ['lang:' + lang.value]
59
- : []
57
+ const facetFilters: string[] = props.multilang ? ['lang:' + lang.value] : []
60
58
 
61
59
  if (props.options.searchParameters?.facetFilters) {
62
60
  facetFilters.push(...props.options.searchParameters.facetFilters)
63
61
  }
64
62
 
65
- watch(
66
- lang,
67
- (newLang, oldLang) => {
68
- const index = facetFilters.findIndex(
69
- (filter) => filter === 'lang:' + oldLang
70
- )
71
- if (index > -1) {
72
- facetFilters.splice(index, 1, 'lang:' + newLang)
73
- }
63
+ watch(lang, (newLang, oldLang) => {
64
+ const index = facetFilters.findIndex((filter) => filter === 'lang:' + oldLang)
65
+ if (index > -1) {
66
+ facetFilters.splice(index, 1, 'lang:' + newLang)
74
67
  }
75
- )
68
+ })
76
69
 
77
70
  function initialize(userOptions: any) {
78
71
  docsearch(
@@ -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()
@@ -7,7 +7,7 @@ const { theme, page } = useData()
7
7
  const hasLastUpdated = computed(() => {
8
8
  const lu = theme.value.lastUpdated
9
9
 
10
- return lu !== undefined && lu !== false
10
+ return lu !== undefined && lu !== false && page.value.lastUpdated !== 0
11
11
  })
12
12
 
13
13
  const prefix = computed(() => {
@@ -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-777539c0.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');
@@ -11,7 +11,7 @@ export declare function build(root: string, buildOptions?: BuildOptions & {
11
11
  mpa?: string;
12
12
  }): Promise<void>;
13
13
 
14
- export declare const createMarkdownRenderer: (srcDir: string, options?: MarkdownOptions) => MarkdownRenderer;
14
+ export declare const createMarkdownRenderer: (srcDir: string, options: MarkdownOptions | undefined, base: string) => MarkdownRenderer;
15
15
 
16
16
  export declare function createServer(root?: string, serverOptions?: ServerOptions): Promise<ViteDevServer>;
17
17
 
@@ -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-777539c0.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');