@vuepress/client 2.0.0-rc.5 → 2.0.0-rc.7

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/app.js CHANGED
@@ -2,31 +2,33 @@ import {
2
2
  ClientOnly,
3
3
  Content,
4
4
  RouteLink,
5
- layoutsSymbol,
6
- pageDataSymbol,
7
- pageFrontmatterSymbol,
8
- pageHeadSymbol,
9
- pageHeadTitleSymbol,
10
- pageLangSymbol,
11
- pageLayoutSymbol,
5
+ clientDataSymbol,
6
+ redirects,
12
7
  resolveRoute,
13
8
  resolvers,
14
- routeLocaleSymbol,
15
9
  routes,
16
- siteData,
17
- siteLocaleDataSymbol,
18
10
  updateHeadSymbol,
19
11
  usePageHead,
20
12
  usePageLang,
21
13
  usePageLayout,
22
14
  withBase
23
- } from "./chunk-VSQZBVKH.js";
15
+ } from "./chunk-VWNFZFFH.js";
24
16
 
25
17
  // src/app.ts
26
18
  import { clientConfigs } from "@internal/clientConfigs";
27
19
  import { createApp, createSSRApp, h } from "vue";
28
20
 
29
- // src/createVueRouter.ts
21
+ // src/internal/siteData.ts
22
+ import { siteData as siteDataRaw } from "@internal/siteData";
23
+ import { shallowRef } from "vue";
24
+ var siteData = shallowRef(siteDataRaw);
25
+ if (__VUEPRESS_DEV__ && (import.meta.webpackHot || import.meta.hot)) {
26
+ __VUE_HMR_RUNTIME__.updateSiteData = (data) => {
27
+ siteData.value = data;
28
+ };
29
+ }
30
+
31
+ // src/router/createVueRouter.ts
30
32
  import { removeEndingSlash } from "@vuepress/shared";
31
33
  import {
32
34
  createMemoryHistory,
@@ -64,8 +66,8 @@ var createVueRouter = () => {
64
66
  to.meta = {
65
67
  // attach route meta
66
68
  ...route.meta,
67
- // attach page data to route meta to trigger page data computed when route changes
68
- _data: pageChunk.data
69
+ // attach page chunk route meta
70
+ _pageChunk: pageChunk
69
71
  };
70
72
  }
71
73
  });
@@ -84,17 +86,17 @@ import { computedWithControl } from "@vueuse/core";
84
86
  import { computed } from "vue";
85
87
  var setupGlobalComputed = (app, router, clientConfigs2) => {
86
88
  const routePath = computed(() => router.currentRoute.value.path);
87
- const pageData = computedWithControl(
89
+ const pageChunk = computedWithControl(
88
90
  routePath,
89
- () => router.currentRoute.value.meta._data
91
+ () => router.currentRoute.value.meta._pageChunk
90
92
  );
91
93
  if (__VUEPRESS_DEV__ && (import.meta.webpackHot || import.meta.hot)) {
92
- __VUE_HMR_RUNTIME__.updatePageData = async (data) => {
93
- const pageChunk = await routes.value[data.path].loader();
94
- routes.value[data.path].loader = () => Promise.resolve({ comp: pageChunk.comp, data });
95
- if (data.path === router.currentRoute.value.meta._data?.path) {
96
- router.currentRoute.value.meta._data = data;
97
- pageData.trigger();
94
+ __VUE_HMR_RUNTIME__.updatePageData = async (newPageData) => {
95
+ const oldPageChunk = await routes.value[newPageData.path].loader();
96
+ routes.value[newPageData.path].loader = () => Promise.resolve({ comp: oldPageChunk.comp, data: newPageData });
97
+ if (newPageData.path === router.currentRoute.value.meta._pageChunk?.data.path) {
98
+ router.currentRoute.value.meta._pageChunk.data = newPageData;
99
+ pageChunk.trigger();
98
100
  }
99
101
  };
100
102
  }
@@ -105,9 +107,9 @@ var setupGlobalComputed = (app, router, clientConfigs2) => {
105
107
  const siteLocaleData = computed(
106
108
  () => resolvers.resolveSiteLocaleData(siteData.value, routeLocale.value)
107
109
  );
108
- const pageFrontmatter = computed(
109
- () => resolvers.resolvePageFrontmatter(pageData.value)
110
- );
110
+ const pageComponent = computed(() => pageChunk.value.comp);
111
+ const pageData = computed(() => pageChunk.value.data);
112
+ const pageFrontmatter = computed(() => pageData.value.frontmatter);
111
113
  const pageHeadTitle = computed(
112
114
  () => resolvers.resolvePageHeadTitle(pageData.value, siteLocaleData.value)
113
115
  );
@@ -124,38 +126,35 @@ var setupGlobalComputed = (app, router, clientConfigs2) => {
124
126
  const pageLayout = computed(
125
127
  () => resolvers.resolvePageLayout(pageData.value, layouts.value)
126
128
  );
127
- app.provide(layoutsSymbol, layouts);
128
- app.provide(pageDataSymbol, pageData);
129
- app.provide(pageFrontmatterSymbol, pageFrontmatter);
130
- app.provide(pageHeadTitleSymbol, pageHeadTitle);
131
- app.provide(pageHeadSymbol, pageHead);
132
- app.provide(pageLangSymbol, pageLang);
133
- app.provide(pageLayoutSymbol, pageLayout);
134
- app.provide(routeLocaleSymbol, routeLocale);
135
- app.provide(siteLocaleDataSymbol, siteLocaleData);
136
- Object.defineProperties(app.config.globalProperties, {
137
- $frontmatter: { get: () => pageFrontmatter.value },
138
- $head: { get: () => pageHead.value },
139
- $headTitle: { get: () => pageHeadTitle.value },
140
- $lang: { get: () => pageLang.value },
141
- $page: { get: () => pageData.value },
142
- $routeLocale: { get: () => routeLocale.value },
143
- $site: { get: () => siteData.value },
144
- $siteLocale: { get: () => siteLocaleData.value },
145
- $withBase: { get: () => withBase }
146
- });
147
- return {
129
+ const clientData = {
148
130
  layouts,
149
131
  pageData,
132
+ pageComponent,
150
133
  pageFrontmatter,
151
134
  pageHead,
152
135
  pageHeadTitle,
153
136
  pageLang,
154
137
  pageLayout,
138
+ redirects,
155
139
  routeLocale,
140
+ routePath,
141
+ routes,
156
142
  siteData,
157
143
  siteLocaleData
158
144
  };
145
+ app.provide(clientDataSymbol, clientData);
146
+ Object.defineProperties(app.config.globalProperties, {
147
+ $frontmatter: { get: () => pageFrontmatter.value },
148
+ $head: { get: () => pageHead.value },
149
+ $headTitle: { get: () => pageHeadTitle.value },
150
+ $lang: { get: () => pageLang.value },
151
+ $page: { get: () => pageData.value },
152
+ $routeLocale: { get: () => routeLocale.value },
153
+ $site: { get: () => siteData.value },
154
+ $siteLocale: { get: () => siteLocaleData.value },
155
+ $withBase: { get: () => withBase }
156
+ });
157
+ return clientData;
159
158
  };
160
159
 
161
160
  // src/setupUpdateHead.ts
@@ -280,8 +279,8 @@ var createVueApp = async () => {
280
279
  const rootComponents = clientConfigs.flatMap(
281
280
  ({ rootComponents: rootComponents2 = [] }) => rootComponents2.map((component) => h(component))
282
281
  );
283
- const layout = usePageLayout();
284
- return () => [h(layout.value), rootComponents];
282
+ const pageLayout = usePageLayout();
283
+ return () => [h(pageLayout.value), rootComponents];
285
284
  }
286
285
  });
287
286
  const router = createVueRouter();
@@ -0,0 +1,280 @@
1
+ // src/composables/clientData.ts
2
+ import { inject } from "vue";
3
+ var clientDataSymbol = Symbol(
4
+ __VUEPRESS_DEV__ ? "clientData" : ""
5
+ );
6
+ var useClientData = () => {
7
+ const clientData = inject(clientDataSymbol);
8
+ if (!clientData) {
9
+ throw new Error("useClientData() is called without provider.");
10
+ }
11
+ return clientData;
12
+ };
13
+
14
+ // src/composables/clientDataUtils.ts
15
+ var useLayouts = () => useClientData().layouts;
16
+ var usePageComponent = () => useClientData().pageComponent;
17
+ var usePageData = () => useClientData().pageData;
18
+ var usePageFrontmatter = () => useClientData().pageFrontmatter;
19
+ var usePageHead = () => useClientData().pageHead;
20
+ var usePageLang = () => useClientData().pageLang;
21
+ var usePageLayout = () => useClientData().pageLayout;
22
+ var useRedirects = () => useClientData().redirects;
23
+ var useRouteLocale = () => useClientData().routeLocale;
24
+ var useRoutePath = () => useClientData().routePath;
25
+ var useRoutes = () => useClientData().routes;
26
+ var useSiteData = () => useClientData().siteData;
27
+ var useSiteLocaleData = () => useClientData().siteLocaleData;
28
+
29
+ // src/composables/updateHead.ts
30
+ import { inject as inject2 } from "vue";
31
+ var updateHeadSymbol = Symbol(
32
+ __VUEPRESS_DEV__ ? "updateHead" : ""
33
+ );
34
+ var useUpdateHead = () => {
35
+ const updateHead = inject2(updateHeadSymbol);
36
+ if (!updateHead) {
37
+ throw new Error("useUpdateHead() is called without provider.");
38
+ }
39
+ return updateHead;
40
+ };
41
+
42
+ // src/router/resolveRoutePath.ts
43
+ import { normalizeRoutePath } from "@vuepress/shared";
44
+
45
+ // src/internal/routes.ts
46
+ import {
47
+ redirects as redirectsRaw,
48
+ routes as routesRaw
49
+ } from "@internal/routes";
50
+ import { shallowRef } from "vue";
51
+ var redirects = shallowRef(redirectsRaw);
52
+ var routes = shallowRef(routesRaw);
53
+ if (__VUEPRESS_DEV__ && (import.meta.webpackHot || import.meta.hot)) {
54
+ __VUE_HMR_RUNTIME__.updateRedirects = (data) => {
55
+ redirects.value = data;
56
+ };
57
+ __VUE_HMR_RUNTIME__.updateRoutes = (data) => {
58
+ routes.value = data;
59
+ };
60
+ }
61
+
62
+ // src/router/resolveRoutePath.ts
63
+ var resolveRoutePath = (path) => {
64
+ const normalizedPath = normalizeRoutePath(path);
65
+ if (routes.value[normalizedPath])
66
+ return normalizedPath;
67
+ const encodedPath = encodeURI(normalizedPath);
68
+ if (routes.value[encodedPath])
69
+ return encodedPath;
70
+ return redirects.value[normalizedPath] || normalizedPath;
71
+ };
72
+
73
+ // src/router/resolveRoute.ts
74
+ var resolveRoute = (path) => {
75
+ const routePath = resolveRoutePath(path);
76
+ const route = routes.value[routePath] ?? {
77
+ ...routes.value["/404.html"],
78
+ notFound: true
79
+ };
80
+ return {
81
+ path: routePath,
82
+ notFound: false,
83
+ ...route
84
+ };
85
+ };
86
+
87
+ // src/components/ClientOnly.ts
88
+ import { defineComponent, onMounted, ref } from "vue";
89
+ var ClientOnly = defineComponent({
90
+ name: "ClientOnly",
91
+ setup(_, ctx) {
92
+ const isMounted = ref(false);
93
+ onMounted(() => {
94
+ isMounted.value = true;
95
+ });
96
+ return () => isMounted.value ? ctx.slots.default?.() : null;
97
+ }
98
+ });
99
+
100
+ // src/router/index.ts
101
+ import { useRoute, useRouter } from "vue-router";
102
+
103
+ // src/components/Content.ts
104
+ import { computed, defineAsyncComponent, defineComponent as defineComponent2, h } from "vue";
105
+ var Content = defineComponent2({
106
+ // eslint-disable-next-line vue/no-reserved-component-names
107
+ name: "Content",
108
+ props: {
109
+ path: {
110
+ type: String,
111
+ required: false,
112
+ default: ""
113
+ }
114
+ },
115
+ setup(props) {
116
+ const pageComponent = usePageComponent();
117
+ const ContentComponent = computed(() => {
118
+ if (!props.path)
119
+ return pageComponent.value;
120
+ const route = resolveRoute(props.path);
121
+ return defineAsyncComponent(() => route.loader().then(({ comp }) => comp));
122
+ });
123
+ return () => h(ContentComponent.value);
124
+ }
125
+ });
126
+
127
+ // src/utils/withBase.ts
128
+ import { isLinkHttp, removeLeadingSlash } from "@vuepress/shared";
129
+ var withBase = (url) => {
130
+ if (isLinkHttp(url))
131
+ return url;
132
+ return `${__VUEPRESS_BASE__}${removeLeadingSlash(url)}`;
133
+ };
134
+
135
+ // src/components/RouteLink.ts
136
+ import { h as h2 } from "vue";
137
+ import { useRouter as useRouter2 } from "vue-router";
138
+ var guardEvent = (event) => {
139
+ if (event.metaKey || event.altKey || event.ctrlKey || event.shiftKey)
140
+ return;
141
+ if (event.defaultPrevented)
142
+ return;
143
+ if (event.button !== void 0 && event.button !== 0)
144
+ return;
145
+ if (event.currentTarget) {
146
+ const target = event.currentTarget.getAttribute("target");
147
+ if (target?.match(/\b_blank\b/i))
148
+ return;
149
+ }
150
+ event.preventDefault();
151
+ return true;
152
+ };
153
+ var RouteLink = ({ active = false, activeClass = "route-link-active", to, ...attrs }, { slots }) => {
154
+ const router = useRouter2();
155
+ const path = withBase(resolveRoutePath(to));
156
+ return h2(
157
+ "a",
158
+ {
159
+ ...attrs,
160
+ class: ["route-link", { [activeClass]: active }],
161
+ href: path,
162
+ onClick: (event = {}) => {
163
+ guardEvent(event) ? router.push(to).catch() : Promise.resolve();
164
+ }
165
+ },
166
+ slots.default?.()
167
+ );
168
+ };
169
+ RouteLink.displayName = "RouteLink";
170
+ RouteLink.props = {
171
+ active: Boolean,
172
+ activeClass: String,
173
+ to: String
174
+ };
175
+
176
+ // src/resolvers.ts
177
+ import { dedupeHead, isString, resolveLocalePath } from "@vuepress/shared";
178
+ import { reactive } from "vue";
179
+
180
+ // src/constants.ts
181
+ var LAYOUT_NAME_DEFAULT = "Layout";
182
+ var LANG_DEFAULT = "en-US";
183
+
184
+ // src/resolvers.ts
185
+ var resolvers = reactive({
186
+ /**
187
+ * Resolve layouts component map
188
+ */
189
+ resolveLayouts: (clientConfigs) => clientConfigs.reduce(
190
+ (prev, item) => ({
191
+ ...prev,
192
+ ...item.layouts
193
+ }),
194
+ {}
195
+ ),
196
+ /**
197
+ * Merge the head config in frontmatter and site locale
198
+ *
199
+ * Frontmatter should take priority over site locale
200
+ */
201
+ resolvePageHead: (pageHeadTitle, pageFrontmatter, siteLocaleDate) => {
202
+ const description = isString(pageFrontmatter.description) ? pageFrontmatter.description : siteLocaleDate.description;
203
+ const head = [
204
+ ...Array.isArray(pageFrontmatter.head) ? pageFrontmatter.head : [],
205
+ ...siteLocaleDate.head,
206
+ ["title", {}, pageHeadTitle],
207
+ ["meta", { name: "description", content: description }]
208
+ ];
209
+ return dedupeHead(head);
210
+ },
211
+ /**
212
+ * Resolve the content of page head title
213
+ *
214
+ * It would be used as the content of the `<title>` tag
215
+ */
216
+ resolvePageHeadTitle: (pageData, siteLocaleDate) => [pageData.title, siteLocaleDate.title].filter((item) => !!item).join(" | "),
217
+ /**
218
+ * Resolve page language from page data
219
+ *
220
+ * It would be used as the `lang` attribute of `<html>` tag
221
+ */
222
+ resolvePageLang: (pageData, siteLocaleData) => pageData.lang || siteLocaleData.lang || LANG_DEFAULT,
223
+ /**
224
+ * Resolve layout component of current page
225
+ */
226
+ resolvePageLayout: (pageData, layouts) => {
227
+ const layoutName = isString(pageData.frontmatter.layout) ? pageData.frontmatter.layout : LAYOUT_NAME_DEFAULT;
228
+ return layouts[layoutName];
229
+ },
230
+ /**
231
+ * Resolve locale path according to route path and locales config
232
+ */
233
+ resolveRouteLocale: (locales, routePath) => resolveLocalePath(locales, routePath),
234
+ /**
235
+ * Resolve site data for specific locale
236
+ *
237
+ * It would merge the locales fields to the root fields
238
+ */
239
+ resolveSiteLocaleData: (siteData, routeLocale) => ({
240
+ ...siteData,
241
+ ...siteData.locales[routeLocale],
242
+ head: [
243
+ // when merging head, the locales head should be placed before root head
244
+ // to get higher priority
245
+ ...siteData.locales[routeLocale]?.head ?? [],
246
+ ...siteData.head ?? []
247
+ ]
248
+ })
249
+ });
250
+
251
+ export {
252
+ clientDataSymbol,
253
+ useClientData,
254
+ useLayouts,
255
+ usePageComponent,
256
+ usePageData,
257
+ usePageFrontmatter,
258
+ usePageHead,
259
+ usePageLang,
260
+ usePageLayout,
261
+ useRedirects,
262
+ useRouteLocale,
263
+ useRoutePath,
264
+ useRoutes,
265
+ useSiteData,
266
+ useSiteLocaleData,
267
+ updateHeadSymbol,
268
+ useUpdateHead,
269
+ redirects,
270
+ routes,
271
+ resolveRoutePath,
272
+ resolveRoute,
273
+ ClientOnly,
274
+ useRoute,
275
+ useRouter,
276
+ Content,
277
+ withBase,
278
+ RouteLink,
279
+ resolvers
280
+ };
package/dist/index.d.ts CHANGED
@@ -1,206 +1,75 @@
1
- import { PageData, PageFrontmatter, HeadConfig, SiteData } from '@vuepress/shared';
2
- export { PageData, PageFrontmatter, PageHeader, SiteData } from '@vuepress/shared';
3
1
  import * as vue from 'vue';
4
- import { ComputedRef, InjectionKey, Ref, Component, App, ComponentOptions, HTMLAttributes, FunctionalComponent, VNode } from 'vue';
2
+ import { Component, ComputedRef, Ref, App, HTMLAttributes, FunctionalComponent, VNode, InjectionKey } from 'vue';
3
+ import { PageData, HeadConfig, SiteData, PageFrontmatter } from '@vuepress/shared';
4
+ export { HeadConfig, PageData, PageFrontmatter, PageHeader, SiteData } from '@vuepress/shared';
5
5
  import { Router } from 'vue-router';
6
+ export { RouteLocationNormalizedLoaded, Router, useRoute, useRouter } from 'vue-router';
6
7
  export { C as CreateVueAppFunction } from './createVueAppFunction-YNGNKfE3.js';
7
8
 
8
9
  /**
9
- * Ref wrapper of `Layouts`
10
+ * Name of the default layout
10
11
  */
11
- type LayoutsRef = ComputedRef<Layouts>;
12
- /**
13
- * Injection key for layouts
14
- */
15
- declare const layoutsSymbol: InjectionKey<LayoutsRef>;
12
+ declare const LAYOUT_NAME_DEFAULT = "Layout";
16
13
  /**
17
- * Returns layouts component map
14
+ * Name of the 404 page layout
18
15
  */
19
- declare const useLayouts: () => LayoutsRef;
16
+ declare const LAYOUT_NAME_NOT_FOUND = "NotFound";
20
17
 
21
- /**
22
- * Ref wrapper of `PageData`
23
- */
24
- type PageDataRef<T extends Record<any, any> = Record<never, never>> = Ref<PageData<T>>;
25
- /**
26
- * Injection key for page data
27
- */
28
- declare const pageDataSymbol: InjectionKey<PageDataRef>;
29
- /**
30
- * Returns the ref of the data of current page
31
- */
32
- declare const usePageData: <T extends Record<any, any> = Record<never, never>>() => PageDataRef<T>;
33
-
34
- /**
35
- * Ref wrapper of `PageFrontmatter`
36
- */
37
- type PageFrontmatterRef<T extends Record<any, any> = Record<string, unknown>> = ComputedRef<PageFrontmatter<T>>;
38
- /**
39
- * Injection key for page frontmatter
40
- */
41
- declare const pageFrontmatterSymbol: InjectionKey<PageFrontmatterRef>;
42
- /**
43
- * Returns the ref of the frontmatter of current page
44
- */
45
- declare const usePageFrontmatter: <T extends Record<any, any> = Record<string, unknown>>() => PageFrontmatterRef<T>;
18
+ interface PageChunk {
19
+ comp: Component;
20
+ data: PageData;
21
+ }
22
+ type RouteMeta = Record<string, unknown>;
23
+ interface Route<T extends RouteMeta = RouteMeta> {
24
+ loader: () => Promise<PageChunk>;
25
+ meta: T;
26
+ }
27
+ type Redirects = Record<string, string>;
28
+ type Routes = Record<string, Route>;
46
29
 
47
- /**
48
- * Page head config, which would be used for generate html tags in `<head>`
49
- */
30
+ interface Layouts {
31
+ [LAYOUT_NAME_DEFAULT]: Component;
32
+ [LAYOUT_NAME_NOT_FOUND]: Component;
33
+ [key: string]: Component;
34
+ }
35
+ type PageComponent = Component;
50
36
  type PageHead = HeadConfig[];
51
- /**
52
- * Ref wrapper of `PageHead`
53
- */
54
- type PageHeadRef = ComputedRef<PageHead>;
55
- /**
56
- * Injection key for page head
57
- */
58
- declare const pageHeadSymbol: InjectionKey<PageHeadRef>;
59
- /**
60
- * Returns the ref of the head config of current page
61
- */
62
- declare const usePageHead: () => PageHeadRef;
63
-
64
- /**
65
- * Page head title, which would be used as the content of `head > title` tag
66
- */
67
37
  type PageHeadTitle = string;
68
- /**
69
- * Ref wrapper of `PageHeadTitle`
70
- */
71
- type PageHeadTitleRef = ComputedRef<PageHeadTitle>;
72
- /**
73
- * Injection key for page head title
74
- */
75
- declare const pageHeadTitleSymbol: InjectionKey<PageHeadTitleRef>;
76
- /**
77
- * Returns the ref of the head title of current page
78
- */
79
- declare const usePageHeadTitle: () => PageHeadTitleRef;
80
-
81
- /**
82
- * Page language
83
- */
84
38
  type PageLang = string;
85
- /**
86
- * Ref wrapper of `PageLang`
87
- */
88
- type PageLangRef = ComputedRef<PageLang>;
89
- /**
90
- * Injection key for page language
91
- */
92
- declare const pageLangSymbol: InjectionKey<PageLangRef>;
93
- /**
94
- * Returns the ref of the language of current page
95
- */
96
- declare const usePageLang: () => PageLangRef;
97
-
98
- /**
99
- * Ref wrapper of `PageLayout`
100
- */
101
- type PageLayoutRef = ComputedRef<Component>;
102
- /**
103
- * Injection key for page layout
104
- */
105
- declare const pageLayoutSymbol: InjectionKey<PageLayoutRef>;
106
- /**
107
- * Returns layout component of current page
108
- */
109
- declare const usePageLayout: () => ComputedRef<Component>;
110
-
111
- /**
112
- * Route locale path
113
- */
39
+ type PageLayout = Component;
40
+ type RoutePath = string;
114
41
  type RouteLocale = string;
115
- /**
116
- * Ref wrapper of `RouteLocale`
117
- */
118
- type RouteLocaleRef = Readonly<Ref<RouteLocale>>;
119
- /**
120
- * Injection key for page route locale path
121
- */
122
- declare const routeLocaleSymbol: InjectionKey<RouteLocaleRef>;
123
- /**
124
- * Returns the ref of the route locale path of current page
125
- */
126
- declare const useRouteLocale: () => RouteLocaleRef;
127
-
128
- interface ResolvedRoute<T extends RouteMeta = RouteMeta> extends Route<T> {
129
- path: string;
130
- notFound: boolean;
131
- }
132
- /**
133
- * Resolve route with given path
134
- */
135
- declare const resolveRoute: <T extends RouteMeta = RouteMeta>(path: string) => ResolvedRoute<T>;
136
-
137
- /**
138
- * Resolve route path with given raw path
139
- */
140
- declare const resolveRoutePath: (path: string) => string;
141
-
142
- /**
143
- * Global redirects ref
144
- */
145
- declare const redirects: Ref<Redirects>;
146
- /**
147
- * Global routes ref
148
- */
149
- declare const routes: Ref<Routes>;
150
-
151
- /**
152
- * Returns the ref of pages map
153
- */
154
- declare const useRedirects: () => typeof redirects;
155
- /**
156
- * Returns the ref of routes map
157
- */
158
- declare const useRoutes: () => typeof routes;
159
-
160
- /**
161
- * Ref wrapper of `SiteData`
162
- */
163
- type SiteDataRef = Ref<SiteData>;
164
- /**
165
- * Global site data ref
166
- */
167
- declare const siteData: SiteDataRef;
168
- /**
169
- * Returns the ref of the site data
170
- */
171
- declare const useSiteData: () => SiteDataRef;
172
-
173
- /**
174
- * Site data of current locale
175
- */
176
42
  type SiteLocaleData = SiteData;
177
- /**
178
- * Ref wrapper of `SiteLocaleData`
179
- */
43
+ type LayoutsRef = ComputedRef<Layouts>;
44
+ type PageComponentRef = ComputedRef<PageComponent>;
45
+ type PageDataRef<T extends Record<any, any> = Record<never, never>> = ComputedRef<PageData<T>>;
46
+ type PageFrontmatterRef<T extends Record<any, any> = Record<never, never>> = ComputedRef<PageFrontmatter<T>>;
47
+ type PageHeadRef = ComputedRef<PageHead>;
48
+ type PageHeadTitleRef = ComputedRef<PageHeadTitle>;
49
+ type PageLangRef = ComputedRef<PageLang>;
50
+ type PageLayoutRef = ComputedRef<PageLayout>;
51
+ type RedirectsRef = Ref<Redirects>;
52
+ type RoutePathRef = ComputedRef<RoutePath>;
53
+ type RouteLocaleRef = ComputedRef<RouteLocale>;
54
+ type RoutesRef = Ref<Routes>;
55
+ type SiteDataRef = Ref<SiteData>;
180
56
  type SiteLocaleDataRef = ComputedRef<SiteLocaleData>;
181
- /**
182
- * Injection key for site locale data
183
- */
184
- declare const siteLocaleDataSymbol: InjectionKey<SiteLocaleDataRef>;
185
- /**
186
- * Returns the ref of the site data of current locale
187
- */
188
- declare const useSiteLocaleData: () => SiteLocaleDataRef;
189
-
190
- /**
191
- * A util function to force update `<head>` of current page
192
- */
193
- type UpdateHead = () => void;
194
- /**
195
- * Injection key for `updateHead` util
196
- */
197
- declare const updateHeadSymbol: InjectionKey<UpdateHead>;
198
- /**
199
- * Returns the `updateHead` util
200
- */
201
- declare const useUpdateHead: () => UpdateHead;
202
-
203
- type Layouts = Record<string, Component>;
57
+ interface ClientData {
58
+ layouts: LayoutsRef;
59
+ pageComponent: PageComponentRef;
60
+ pageData: PageDataRef;
61
+ pageFrontmatter: PageFrontmatterRef;
62
+ pageHead: PageHeadRef;
63
+ pageHeadTitle: PageHeadTitleRef;
64
+ pageLang: PageLangRef;
65
+ pageLayout: PageLayoutRef;
66
+ redirects: RedirectsRef;
67
+ routePath: RoutePathRef;
68
+ routeLocale: RouteLocaleRef;
69
+ routes: RoutesRef;
70
+ siteData: SiteDataRef;
71
+ siteLocaleData: SiteLocaleDataRef;
72
+ }
204
73
 
205
74
  /**
206
75
  * Configure vuepress client
@@ -229,18 +98,6 @@ interface ClientConfig {
229
98
  rootComponents?: Component[];
230
99
  }
231
100
 
232
- interface PageChunk {
233
- comp: ComponentOptions;
234
- data: PageData;
235
- }
236
- type RouteMeta = Record<string, unknown>;
237
- interface Route<T extends RouteMeta = RouteMeta> {
238
- loader: () => Promise<PageChunk>;
239
- meta: T;
240
- }
241
- type Redirects = Record<string, string>;
242
- type Routes = Record<string, Route>;
243
-
244
101
  /**
245
102
  * Wrapper component that only renders its content on the client side and skips server side rendering
246
103
  */
@@ -301,14 +158,54 @@ declare const RouteLink: FunctionalComponent<RouteLinkProps, Record<never, never
301
158
  }>;
302
159
 
303
160
  /**
304
- * A helper function to help you define vuepress client config file
161
+ * Injection key for client data
305
162
  */
306
- declare const defineClientConfig: (clientConfig?: ClientConfig) => ClientConfig;
163
+ declare const clientDataSymbol: InjectionKey<ClientData>;
164
+ /**
165
+ * Returns client data
166
+ */
167
+ declare const useClientData: () => ClientData;
168
+
169
+ declare const useLayouts: () => LayoutsRef;
170
+ declare const usePageComponent: () => PageComponentRef;
171
+ declare const usePageData: <T extends Record<any, any> = Record<never, never>>() => PageDataRef<T>;
172
+ declare const usePageFrontmatter: <T extends Record<any, any> = Record<string, unknown>>() => PageFrontmatterRef<T>;
173
+ declare const usePageHead: () => PageHeadRef;
174
+ declare const usePageLang: () => PageLangRef;
175
+ declare const usePageLayout: () => PageLayoutRef;
176
+ declare const useRedirects: () => RedirectsRef;
177
+ declare const useRouteLocale: () => RouteLocaleRef;
178
+ declare const useRoutePath: () => RoutePathRef;
179
+ declare const useRoutes: () => RoutesRef;
180
+ declare const useSiteData: () => SiteDataRef;
181
+ declare const useSiteLocaleData: () => SiteLocaleDataRef;
307
182
 
308
183
  /**
309
- * Prefix url with site base
184
+ * A util function to force update `<head>` of current page
310
185
  */
311
- declare const withBase: (url: string) => string;
186
+ type UpdateHead = () => void;
187
+ /**
188
+ * Injection key for `updateHead` util
189
+ */
190
+ declare const updateHeadSymbol: InjectionKey<UpdateHead>;
191
+ /**
192
+ * Returns the `updateHead` util
193
+ */
194
+ declare const useUpdateHead: () => UpdateHead;
195
+
196
+ interface ResolvedRoute<T extends RouteMeta = RouteMeta> extends Route<T> {
197
+ path: string;
198
+ notFound: boolean;
199
+ }
200
+ /**
201
+ * Resolve route with given path
202
+ */
203
+ declare const resolveRoute: <T extends RouteMeta = RouteMeta>(path: string) => ResolvedRoute<T>;
204
+
205
+ /**
206
+ * Resolve route path with given raw path
207
+ */
208
+ declare const resolveRoutePath: (path: string) => string;
312
209
 
313
210
  /**
314
211
  * Resolver methods to get global computed
@@ -319,13 +216,17 @@ declare const withBase: (url: string) => string;
319
216
  */
320
217
  declare const resolvers: {
321
218
  resolveLayouts: (clientConfigs: ClientConfig[]) => Layouts;
322
- resolvePageFrontmatter: (pageData: PageData) => PageFrontmatter;
323
- resolvePageHead: (headTitle: PageHeadTitle, frontmatter: PageFrontmatter, siteLocale: SiteLocaleData) => PageHead;
324
- resolvePageHeadTitle: (page: PageData, siteLocale: SiteLocaleData) => PageHeadTitle;
325
- resolvePageLang: (page: PageData, siteLocale: SiteLocaleData) => PageLang;
326
- resolvePageLayout: (page: PageData, layouts: Layouts) => Component;
219
+ resolvePageHead: (pageHeadTitle: PageHeadTitle, pageFrontmatter: PageFrontmatter, siteLocaleDate: SiteData) => PageHead;
220
+ resolvePageHeadTitle: (pageData: PageData, siteLocaleDate: SiteData) => PageHeadTitle;
221
+ resolvePageLang: (pageData: PageData, siteLocaleData: SiteData) => PageLang;
222
+ resolvePageLayout: (pageData: PageData, layouts: Layouts) => PageLayout;
327
223
  resolveRouteLocale: (locales: SiteData['locales'], routePath: string) => RouteLocale;
328
- resolveSiteLocaleData: (site: SiteData, routeLocale: RouteLocale) => SiteLocaleData;
224
+ resolveSiteLocaleData: (siteData: SiteData, routeLocale: RouteLocale) => SiteLocaleData;
329
225
  };
330
226
 
331
- export { type ClientConfig, ClientOnly, Content, type Layouts, type LayoutsRef, type PageChunk, type PageDataRef, type PageFrontmatterRef, type PageHead, type PageHeadRef, type PageHeadTitle, type PageHeadTitleRef, type PageLang, type PageLangRef, type PageLayoutRef, type Redirects, type Route, RouteLink, type RouteLinkProps, type RouteLocale, type RouteLocaleRef, type RouteMeta, type Routes, type SiteDataRef, type SiteLocaleData, type SiteLocaleDataRef, type UpdateHead, defineClientConfig, layoutsSymbol, pageDataSymbol, pageFrontmatterSymbol, pageHeadSymbol, pageHeadTitleSymbol, pageLangSymbol, pageLayoutSymbol, redirects, resolveRoute, resolveRoutePath, resolvers, routeLocaleSymbol, routes, siteData, siteLocaleDataSymbol, updateHeadSymbol, useLayouts, usePageData, usePageFrontmatter, usePageHead, usePageHeadTitle, usePageLang, usePageLayout, useRedirects, useRouteLocale, useRoutes, useSiteData, useSiteLocaleData, useUpdateHead, withBase };
227
+ /**
228
+ * Prefix url with site base
229
+ */
230
+ declare const withBase: (url: string) => string;
231
+
232
+ export { type ClientConfig, type ClientData, ClientOnly, Content, type Layouts, type LayoutsRef, type PageChunk, type PageComponent, type PageComponentRef, type PageDataRef, type PageFrontmatterRef, type PageHead, type PageHeadRef, type PageHeadTitle, type PageHeadTitleRef, type PageLang, type PageLangRef, type PageLayout, type PageLayoutRef, type Redirects, type RedirectsRef, type Route, RouteLink, type RouteLinkProps, type RouteLocale, type RouteLocaleRef, type RouteMeta, type RoutePath, type RoutePathRef, type Routes, type RoutesRef, type SiteDataRef, type SiteLocaleData, type SiteLocaleDataRef, type UpdateHead, clientDataSymbol, resolveRoute, resolveRoutePath, resolvers, updateHeadSymbol, useClientData, useLayouts, usePageComponent, usePageData, usePageFrontmatter, usePageHead, usePageLang, usePageLayout, useRedirects, useRouteLocale, useRoutePath, useRoutes, useSiteData, useSiteLocaleData, useUpdateHead, withBase };
package/dist/index.js CHANGED
@@ -2,68 +2,52 @@ import {
2
2
  ClientOnly,
3
3
  Content,
4
4
  RouteLink,
5
- defineClientConfig,
6
- layoutsSymbol,
7
- pageDataSymbol,
8
- pageFrontmatterSymbol,
9
- pageHeadSymbol,
10
- pageHeadTitleSymbol,
11
- pageLangSymbol,
12
- pageLayoutSymbol,
13
- redirects,
5
+ clientDataSymbol,
14
6
  resolveRoute,
15
7
  resolveRoutePath,
16
8
  resolvers,
17
- routeLocaleSymbol,
18
- routes,
19
- siteData,
20
- siteLocaleDataSymbol,
21
9
  updateHeadSymbol,
10
+ useClientData,
22
11
  useLayouts,
12
+ usePageComponent,
23
13
  usePageData,
24
14
  usePageFrontmatter,
25
15
  usePageHead,
26
- usePageHeadTitle,
27
16
  usePageLang,
28
17
  usePageLayout,
29
18
  useRedirects,
19
+ useRoute,
30
20
  useRouteLocale,
21
+ useRoutePath,
22
+ useRouter,
31
23
  useRoutes,
32
24
  useSiteData,
33
25
  useSiteLocaleData,
34
26
  useUpdateHead,
35
27
  withBase
36
- } from "./chunk-VSQZBVKH.js";
28
+ } from "./chunk-VWNFZFFH.js";
37
29
  export {
38
30
  ClientOnly,
39
31
  Content,
40
32
  RouteLink,
41
- defineClientConfig,
42
- layoutsSymbol,
43
- pageDataSymbol,
44
- pageFrontmatterSymbol,
45
- pageHeadSymbol,
46
- pageHeadTitleSymbol,
47
- pageLangSymbol,
48
- pageLayoutSymbol,
49
- redirects,
33
+ clientDataSymbol,
50
34
  resolveRoute,
51
35
  resolveRoutePath,
52
36
  resolvers,
53
- routeLocaleSymbol,
54
- routes,
55
- siteData,
56
- siteLocaleDataSymbol,
57
37
  updateHeadSymbol,
38
+ useClientData,
58
39
  useLayouts,
40
+ usePageComponent,
59
41
  usePageData,
60
42
  usePageFrontmatter,
61
43
  usePageHead,
62
- usePageHeadTitle,
63
44
  usePageLang,
64
45
  usePageLayout,
65
46
  useRedirects,
47
+ useRoute,
66
48
  useRouteLocale,
49
+ useRoutePath,
50
+ useRouter,
67
51
  useRoutes,
68
52
  useSiteData,
69
53
  useSiteLocaleData,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/client",
3
- "version": "2.0.0-rc.5",
3
+ "version": "2.0.0-rc.7",
4
4
  "description": "Client package of VuePress",
5
5
  "keywords": [
6
6
  "vuepress",
@@ -37,7 +37,7 @@
37
37
  "@vueuse/core": "^10.7.2",
38
38
  "vue": "^3.4.15",
39
39
  "vue-router": "^4.2.5",
40
- "@vuepress/shared": "2.0.0-rc.5"
40
+ "@vuepress/shared": "2.0.0-rc.7"
41
41
  },
42
42
  "publishConfig": {
43
43
  "access": "public"
@@ -54,7 +54,6 @@
54
54
  ],
55
55
  "external": [
56
56
  "@internal/clientConfigs",
57
- "@internal/layoutComponents",
58
57
  "@internal/routes",
59
58
  "@internal/siteData"
60
59
  ],
@@ -1,400 +0,0 @@
1
- // src/composables/layouts.ts
2
- import { inject } from "vue";
3
- var layoutsSymbol = Symbol(
4
- __VUEPRESS_DEV__ ? "layouts" : ""
5
- );
6
- var useLayouts = () => {
7
- const layouts = inject(layoutsSymbol);
8
- if (!layouts) {
9
- throw new Error("useLayouts() is called without provider.");
10
- }
11
- return layouts;
12
- };
13
-
14
- // src/composables/pageData.ts
15
- import { inject as inject2 } from "vue";
16
- var pageDataSymbol = Symbol(
17
- __VUEPRESS_DEV__ ? "pageData" : ""
18
- );
19
- var usePageData = () => {
20
- const pageData = inject2(pageDataSymbol);
21
- if (!pageData) {
22
- throw new Error("pageData() is called without provider.");
23
- }
24
- return pageData;
25
- };
26
-
27
- // src/composables/pageFrontmatter.ts
28
- import { inject as inject3 } from "vue";
29
- var pageFrontmatterSymbol = Symbol(
30
- __VUEPRESS_DEV__ ? "pageFrontmatter" : ""
31
- );
32
- var usePageFrontmatter = () => {
33
- const pageFrontmatter = inject3(pageFrontmatterSymbol);
34
- if (!pageFrontmatter) {
35
- throw new Error("usePageFrontmatter() is called without provider.");
36
- }
37
- return pageFrontmatter;
38
- };
39
-
40
- // src/composables/pageHead.ts
41
- import { inject as inject4 } from "vue";
42
- var pageHeadSymbol = Symbol(
43
- __VUEPRESS_DEV__ ? "pageHead" : ""
44
- );
45
- var usePageHead = () => {
46
- const pageHead = inject4(pageHeadSymbol);
47
- if (!pageHead) {
48
- throw new Error("usePageHead() is called without provider.");
49
- }
50
- return pageHead;
51
- };
52
-
53
- // src/composables/pageHeadTitle.ts
54
- import { inject as inject5 } from "vue";
55
- var pageHeadTitleSymbol = Symbol(
56
- __VUEPRESS_DEV__ ? "pageHeadTitle" : ""
57
- );
58
- var usePageHeadTitle = () => {
59
- const pageHeadTitle = inject5(pageHeadTitleSymbol);
60
- if (!pageHeadTitle) {
61
- throw new Error("usePageHeadTitle() is called without provider.");
62
- }
63
- return pageHeadTitle;
64
- };
65
-
66
- // src/composables/pageLang.ts
67
- import { inject as inject6 } from "vue";
68
- var pageLangSymbol = Symbol(
69
- __VUEPRESS_DEV__ ? "pageLang" : ""
70
- );
71
- var usePageLang = () => {
72
- const pageLang = inject6(pageLangSymbol);
73
- if (!pageLang) {
74
- throw new Error("usePageLang() is called without provider.");
75
- }
76
- return pageLang;
77
- };
78
-
79
- // src/composables/pageLayout.ts
80
- import { inject as inject7 } from "vue";
81
- var pageLayoutSymbol = Symbol(
82
- __VUEPRESS_DEV__ ? "pageLayout" : ""
83
- );
84
- var usePageLayout = () => {
85
- const pageLayout = inject7(pageLayoutSymbol);
86
- if (!pageLayout) {
87
- throw new Error("usePageLayout() is called without provider.");
88
- }
89
- return pageLayout;
90
- };
91
-
92
- // src/composables/routeLocale.ts
93
- import { inject as inject8 } from "vue";
94
- var routeLocaleSymbol = Symbol(
95
- __VUEPRESS_DEV__ ? "routeLocale" : ""
96
- );
97
- var useRouteLocale = () => {
98
- const routeLocale = inject8(routeLocaleSymbol);
99
- if (!routeLocale) {
100
- throw new Error("useRouteLocale() is called without provider.");
101
- }
102
- return routeLocale;
103
- };
104
-
105
- // src/router/routes.ts
106
- import {
107
- redirects as redirectsRaw,
108
- routes as routesRaw
109
- } from "@internal/routes";
110
- import { shallowRef } from "vue";
111
- var redirects = shallowRef(redirectsRaw);
112
- var routes = shallowRef(routesRaw);
113
- if (__VUEPRESS_DEV__ && (import.meta.webpackHot || import.meta.hot)) {
114
- __VUE_HMR_RUNTIME__.updateRedirects = (data) => {
115
- redirects.value = data;
116
- };
117
- __VUE_HMR_RUNTIME__.updateRoutes = (data) => {
118
- routes.value = data;
119
- };
120
- }
121
-
122
- // src/router/resolveRoutePath.ts
123
- import { normalizeRoutePath } from "@vuepress/shared";
124
- var resolveRoutePath = (path) => {
125
- const normalizedPath = normalizeRoutePath(path);
126
- if (routes.value[normalizedPath])
127
- return normalizedPath;
128
- const encodedPath = encodeURI(normalizedPath);
129
- if (routes.value[encodedPath])
130
- return encodedPath;
131
- return redirects.value[normalizedPath] || normalizedPath;
132
- };
133
-
134
- // src/router/resolveRoute.ts
135
- var resolveRoute = (path) => {
136
- const routePath = resolveRoutePath(path);
137
- const route = routes.value[routePath] ?? {
138
- ...routes.value["/404.html"],
139
- notFound: true
140
- };
141
- return {
142
- path: routePath,
143
- notFound: false,
144
- ...route
145
- };
146
- };
147
-
148
- // src/composables/routes.ts
149
- var useRedirects = () => redirects;
150
- var useRoutes = () => routes;
151
-
152
- // src/composables/siteData.ts
153
- import { siteData as siteDataRaw } from "@internal/siteData";
154
- import { shallowRef as shallowRef2 } from "vue";
155
- var siteData = shallowRef2(siteDataRaw);
156
- var useSiteData = () => siteData;
157
- if (__VUEPRESS_DEV__ && (import.meta.webpackHot || import.meta.hot)) {
158
- __VUE_HMR_RUNTIME__.updateSiteData = (data) => {
159
- siteData.value = data;
160
- };
161
- }
162
-
163
- // src/composables/siteLocaleData.ts
164
- import { inject as inject9 } from "vue";
165
- var siteLocaleDataSymbol = Symbol(
166
- __VUEPRESS_DEV__ ? "siteLocaleData" : ""
167
- );
168
- var useSiteLocaleData = () => {
169
- const siteLocaleData = inject9(siteLocaleDataSymbol);
170
- if (!siteLocaleData) {
171
- throw new Error("useSiteLocaleData() is called without provider.");
172
- }
173
- return siteLocaleData;
174
- };
175
-
176
- // src/composables/updateHead.ts
177
- import { inject as inject10 } from "vue";
178
- var updateHeadSymbol = Symbol(
179
- __VUEPRESS_DEV__ ? "updateHead" : ""
180
- );
181
- var useUpdateHead = () => {
182
- const updateHead = inject10(updateHeadSymbol);
183
- if (!updateHead) {
184
- throw new Error("useUpdateHead() is called without provider.");
185
- }
186
- return updateHead;
187
- };
188
-
189
- // src/components/ClientOnly.ts
190
- import { defineComponent, onMounted, ref } from "vue";
191
- var ClientOnly = defineComponent({
192
- name: "ClientOnly",
193
- setup(_, ctx) {
194
- const isMounted = ref(false);
195
- onMounted(() => {
196
- isMounted.value = true;
197
- });
198
- return () => isMounted.value ? ctx.slots.default?.() : null;
199
- }
200
- });
201
-
202
- // src/components/Content.ts
203
- import { computed, defineAsyncComponent, defineComponent as defineComponent2, h } from "vue";
204
- var Content = defineComponent2({
205
- // eslint-disable-next-line vue/no-reserved-component-names
206
- name: "Content",
207
- props: {
208
- path: {
209
- type: String,
210
- required: false,
211
- default: ""
212
- }
213
- },
214
- setup(props) {
215
- const pageData = usePageData();
216
- const pageComponent = computed(() => {
217
- const route = resolveRoute(props.path || pageData.value.path);
218
- return defineAsyncComponent(() => route.loader().then(({ comp }) => comp));
219
- });
220
- return () => h(pageComponent.value);
221
- }
222
- });
223
-
224
- // src/helpers/defineClientConfig.ts
225
- var defineClientConfig = (clientConfig = {}) => clientConfig;
226
-
227
- // src/helpers/withBase.ts
228
- import { isLinkHttp, removeLeadingSlash } from "@vuepress/shared";
229
- var withBase = (url) => {
230
- if (isLinkHttp(url))
231
- return url;
232
- return `${__VUEPRESS_BASE__}${removeLeadingSlash(url)}`;
233
- };
234
-
235
- // src/components/RouteLink.ts
236
- import { h as h2 } from "vue";
237
- import { useRouter } from "vue-router";
238
- var guardEvent = (event) => {
239
- if (event.metaKey || event.altKey || event.ctrlKey || event.shiftKey)
240
- return;
241
- if (event.defaultPrevented)
242
- return;
243
- if (event.button !== void 0 && event.button !== 0)
244
- return;
245
- if (event.currentTarget) {
246
- const target = event.currentTarget.getAttribute("target");
247
- if (target?.match(/\b_blank\b/i))
248
- return;
249
- }
250
- event.preventDefault();
251
- return true;
252
- };
253
- var RouteLink = ({ active = false, activeClass = "route-link-active", to, ...attrs }, { slots }) => {
254
- const router = useRouter();
255
- const path = withBase(resolveRoutePath(to));
256
- return h2(
257
- "a",
258
- {
259
- ...attrs,
260
- class: ["route-link", { [activeClass]: active }],
261
- href: path,
262
- onClick: (event = {}) => {
263
- guardEvent(event) ? router.push(to).catch() : Promise.resolve();
264
- }
265
- },
266
- slots.default?.()
267
- );
268
- };
269
- RouteLink.displayName = "RouteLink";
270
- RouteLink.props = {
271
- active: Boolean,
272
- activeClass: String,
273
- to: String
274
- };
275
-
276
- // src/resolvers.ts
277
- import { dedupeHead, isString, resolveLocalePath } from "@vuepress/shared";
278
- import { reactive } from "vue";
279
-
280
- // src/constants.ts
281
- var LAYOUT_NAME_DEFAULT = "Layout";
282
- var LAYOUT_NAME_NOT_FOUND = "NotFound";
283
-
284
- // src/resolvers.ts
285
- var resolvers = reactive({
286
- /**
287
- * Resolve layouts component map
288
- */
289
- resolveLayouts: (clientConfigs) => clientConfigs.reduce(
290
- (prev, item) => ({
291
- ...prev,
292
- ...item.layouts
293
- }),
294
- {}
295
- ),
296
- /**
297
- * Resolve page frontmatter from page data
298
- */
299
- resolvePageFrontmatter: (pageData) => pageData.frontmatter,
300
- /**
301
- * Merge the head config in frontmatter and site locale
302
- *
303
- * Frontmatter should take priority over site locale
304
- */
305
- resolvePageHead: (headTitle, frontmatter, siteLocale) => {
306
- const description = isString(frontmatter.description) ? frontmatter.description : siteLocale.description;
307
- const head = [
308
- ...Array.isArray(frontmatter.head) ? frontmatter.head : [],
309
- ...siteLocale.head,
310
- ["title", {}, headTitle],
311
- ["meta", { name: "description", content: description }]
312
- ];
313
- return dedupeHead(head);
314
- },
315
- /**
316
- * Resolve the content of page head title
317
- *
318
- * It would be used as the content of the `<title>` tag
319
- */
320
- resolvePageHeadTitle: (page, siteLocale) => [page.title, siteLocale.title].filter((item) => !!item).join(" | "),
321
- /**
322
- * Resolve page language from page data
323
- *
324
- * It would be used as the `lang` attribute of `<html>` tag
325
- */
326
- resolvePageLang: (page, siteLocale) => page.lang || siteLocale.lang || "en-US",
327
- /**
328
- * Resolve layout component of current page
329
- */
330
- resolvePageLayout: (page, layouts) => {
331
- let layoutName;
332
- if (page.path) {
333
- const frontmatterLayout = page.frontmatter.layout;
334
- if (isString(frontmatterLayout)) {
335
- layoutName = frontmatterLayout;
336
- } else {
337
- layoutName = LAYOUT_NAME_DEFAULT;
338
- }
339
- } else {
340
- layoutName = LAYOUT_NAME_NOT_FOUND;
341
- }
342
- return layouts[layoutName];
343
- },
344
- /**
345
- * Resolve locale path according to route path and locales config
346
- */
347
- resolveRouteLocale: (locales, routePath) => resolveLocalePath(locales, routePath),
348
- /**
349
- * Resolve site data for specific locale
350
- *
351
- * It would merge the locales fields to the root fields
352
- */
353
- resolveSiteLocaleData: (site, routeLocale) => ({
354
- ...site,
355
- ...site.locales[routeLocale],
356
- head: [
357
- // when merging head, the locales head should be placed before root head
358
- // to get higher priority
359
- ...site.locales[routeLocale]?.head ?? [],
360
- ...site.head ?? []
361
- ]
362
- })
363
- });
364
-
365
- export {
366
- layoutsSymbol,
367
- useLayouts,
368
- pageDataSymbol,
369
- usePageData,
370
- pageFrontmatterSymbol,
371
- usePageFrontmatter,
372
- pageHeadSymbol,
373
- usePageHead,
374
- pageHeadTitleSymbol,
375
- usePageHeadTitle,
376
- pageLangSymbol,
377
- usePageLang,
378
- pageLayoutSymbol,
379
- usePageLayout,
380
- routeLocaleSymbol,
381
- useRouteLocale,
382
- redirects,
383
- routes,
384
- resolveRoutePath,
385
- resolveRoute,
386
- useRedirects,
387
- useRoutes,
388
- siteData,
389
- useSiteData,
390
- siteLocaleDataSymbol,
391
- useSiteLocaleData,
392
- updateHeadSymbol,
393
- useUpdateHead,
394
- ClientOnly,
395
- Content,
396
- defineClientConfig,
397
- withBase,
398
- RouteLink,
399
- resolvers
400
- };