@vuepress/client 2.0.0-rc.1 → 2.0.0-rc.11
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.d.ts +1 -1
- package/dist/app.js +85 -120
- package/dist/chunk-MPZOAYAQ.js +397 -0
- package/dist/index.d.ts +257 -203
- package/dist/index.js +25 -29
- package/dist/{setupDevtools-X4YFRK4B.js → setupDevtools-H6KAGBNI.js} +16 -16
- package/package.json +6 -10
- package/dist/chunk-PEQEPZ75.js +0 -339
- /package/dist/{createVueAppFunction-YNGNKfE3.d.ts → createVueAppFunction-onJTVJru.d.ts} +0 -0
package/dist/app.d.ts
CHANGED
package/dist/app.js
CHANGED
|
@@ -1,32 +1,34 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ClientOnly,
|
|
3
3
|
Content,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
pageHeadTitleSymbol,
|
|
9
|
-
pageLangSymbol,
|
|
10
|
-
pageLayoutSymbol,
|
|
11
|
-
pagesData,
|
|
4
|
+
RouteLink,
|
|
5
|
+
clientDataSymbol,
|
|
6
|
+
redirects,
|
|
7
|
+
resolveRoute,
|
|
12
8
|
resolvers,
|
|
13
|
-
|
|
14
|
-
siteData,
|
|
15
|
-
siteLocaleDataSymbol,
|
|
9
|
+
routes,
|
|
16
10
|
updateHeadSymbol,
|
|
17
11
|
usePageHead,
|
|
18
12
|
usePageLang,
|
|
19
13
|
usePageLayout,
|
|
20
14
|
withBase
|
|
21
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-MPZOAYAQ.js";
|
|
22
16
|
|
|
23
17
|
// src/app.ts
|
|
24
18
|
import { clientConfigs } from "@internal/clientConfigs";
|
|
25
|
-
import { createApp, createSSRApp, h
|
|
26
|
-
import { RouterView } from "vue-router";
|
|
19
|
+
import { createApp, createSSRApp, h } from "vue";
|
|
27
20
|
|
|
28
|
-
// src/
|
|
29
|
-
import {
|
|
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,
|
|
@@ -34,67 +36,19 @@ import {
|
|
|
34
36
|
createWebHistory,
|
|
35
37
|
START_LOCATION
|
|
36
38
|
} from "vue-router";
|
|
37
|
-
|
|
38
|
-
// src/routes.ts
|
|
39
|
-
import { pagesRoutes } from "@internal/pagesRoutes";
|
|
40
|
-
|
|
41
|
-
// src/components/Vuepress.ts
|
|
42
|
-
import { defineComponent, h } from "vue";
|
|
43
|
-
var Vuepress = defineComponent({
|
|
44
|
-
name: "Vuepress",
|
|
45
|
-
setup() {
|
|
46
|
-
const layout = usePageLayout();
|
|
47
|
-
return () => h(layout.value);
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
// src/routes.ts
|
|
52
|
-
var createRoutes = () => pagesRoutes.reduce(
|
|
53
|
-
(result, [name, path, meta, redirects]) => {
|
|
54
|
-
result.push(
|
|
55
|
-
{
|
|
56
|
-
name,
|
|
57
|
-
path,
|
|
58
|
-
component: Vuepress,
|
|
59
|
-
meta
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
path: path.endsWith("/") ? (
|
|
63
|
-
// redirect from `/index.html` to `/`
|
|
64
|
-
path + "index.html"
|
|
65
|
-
) : (
|
|
66
|
-
// redirect from `/foo` to `/foo.html`
|
|
67
|
-
path.substring(0, path.length - 5)
|
|
68
|
-
),
|
|
69
|
-
redirect: path
|
|
70
|
-
},
|
|
71
|
-
...redirects.map((item) => ({
|
|
72
|
-
path: item === ":md" ? (
|
|
73
|
-
// redirect from `/foo.md` to `/foo.html`
|
|
74
|
-
path.substring(0, path.length - 5) + ".md"
|
|
75
|
-
) : item,
|
|
76
|
-
redirect: path
|
|
77
|
-
}))
|
|
78
|
-
);
|
|
79
|
-
return result;
|
|
80
|
-
},
|
|
81
|
-
[
|
|
82
|
-
{
|
|
83
|
-
name: "404",
|
|
84
|
-
path: "/:catchAll(.*)",
|
|
85
|
-
component: Vuepress
|
|
86
|
-
}
|
|
87
|
-
]
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
// src/router.ts
|
|
91
39
|
var historyCreator = __VUEPRESS_SSR__ ? createMemoryHistory : createWebHistory;
|
|
92
40
|
var createVueRouter = () => {
|
|
93
41
|
const router = createRouter({
|
|
94
42
|
// it might be an issue of vue-router that have to remove the ending slash
|
|
95
43
|
history: historyCreator(removeEndingSlash(__VUEPRESS_BASE__)),
|
|
96
|
-
routes:
|
|
97
|
-
|
|
44
|
+
routes: [
|
|
45
|
+
{
|
|
46
|
+
name: "vuepress-route",
|
|
47
|
+
path: "/:catchAll(.*)",
|
|
48
|
+
components: {}
|
|
49
|
+
}
|
|
50
|
+
],
|
|
51
|
+
scrollBehavior: (to, _from, savedPosition) => {
|
|
98
52
|
if (savedPosition)
|
|
99
53
|
return savedPosition;
|
|
100
54
|
if (to.hash)
|
|
@@ -104,11 +58,19 @@ var createVueRouter = () => {
|
|
|
104
58
|
});
|
|
105
59
|
router.beforeResolve(async (to, from) => {
|
|
106
60
|
if (to.path !== from.path || from === START_LOCATION) {
|
|
107
|
-
;
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
61
|
+
const route = resolveRoute(to.fullPath);
|
|
62
|
+
if (route.path !== to.fullPath) {
|
|
63
|
+
return route.path;
|
|
64
|
+
}
|
|
65
|
+
const pageChunk = await route.loader();
|
|
66
|
+
to.meta = {
|
|
67
|
+
// attach route meta
|
|
68
|
+
...route.meta,
|
|
69
|
+
// attach page chunk route meta
|
|
70
|
+
_pageChunk: pageChunk
|
|
71
|
+
};
|
|
72
|
+
} else if (to.path === from.path) {
|
|
73
|
+
to.meta = from.meta;
|
|
112
74
|
}
|
|
113
75
|
});
|
|
114
76
|
return router;
|
|
@@ -118,23 +80,30 @@ var createVueRouter = () => {
|
|
|
118
80
|
var setupGlobalComponents = (app) => {
|
|
119
81
|
app.component("ClientOnly", ClientOnly);
|
|
120
82
|
app.component("Content", Content);
|
|
83
|
+
app.component("RouteLink", RouteLink);
|
|
121
84
|
};
|
|
122
85
|
|
|
123
86
|
// src/setupGlobalComputed.ts
|
|
124
|
-
import {
|
|
125
|
-
import { computed } from "vue";
|
|
87
|
+
import { computed, customRef } from "vue";
|
|
126
88
|
var setupGlobalComputed = (app, router, clientConfigs2) => {
|
|
127
89
|
const routePath = computed(() => router.currentRoute.value.path);
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
90
|
+
const pageChunk = customRef((track, trigger) => ({
|
|
91
|
+
get() {
|
|
92
|
+
track();
|
|
93
|
+
return router.currentRoute.value.meta._pageChunk;
|
|
94
|
+
},
|
|
95
|
+
set(value) {
|
|
96
|
+
router.currentRoute.value.meta._pageChunk = value;
|
|
97
|
+
trigger();
|
|
98
|
+
}
|
|
99
|
+
}));
|
|
132
100
|
if (__VUEPRESS_DEV__ && (import.meta.webpackHot || import.meta.hot)) {
|
|
133
|
-
__VUE_HMR_RUNTIME__.updatePageData = (
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
101
|
+
__VUE_HMR_RUNTIME__.updatePageData = async (newPageData) => {
|
|
102
|
+
const oldPageChunk = await routes.value[newPageData.path].loader();
|
|
103
|
+
const newPageChunk = { comp: oldPageChunk.comp, data: newPageData };
|
|
104
|
+
routes.value[newPageData.path].loader = () => Promise.resolve(newPageChunk);
|
|
105
|
+
if (newPageData.path === router.currentRoute.value.meta._pageChunk?.data.path) {
|
|
106
|
+
pageChunk.value = newPageChunk;
|
|
138
107
|
}
|
|
139
108
|
};
|
|
140
109
|
}
|
|
@@ -145,9 +114,9 @@ var setupGlobalComputed = (app, router, clientConfigs2) => {
|
|
|
145
114
|
const siteLocaleData = computed(
|
|
146
115
|
() => resolvers.resolveSiteLocaleData(siteData.value, routeLocale.value)
|
|
147
116
|
);
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
);
|
|
117
|
+
const pageComponent = computed(() => pageChunk.value.comp);
|
|
118
|
+
const pageData = computed(() => pageChunk.value.data);
|
|
119
|
+
const pageFrontmatter = computed(() => pageData.value.frontmatter);
|
|
151
120
|
const pageHeadTitle = computed(
|
|
152
121
|
() => resolvers.resolvePageHeadTitle(pageData.value, siteLocaleData.value)
|
|
153
122
|
);
|
|
@@ -164,38 +133,35 @@ var setupGlobalComputed = (app, router, clientConfigs2) => {
|
|
|
164
133
|
const pageLayout = computed(
|
|
165
134
|
() => resolvers.resolvePageLayout(pageData.value, layouts.value)
|
|
166
135
|
);
|
|
167
|
-
|
|
168
|
-
app.provide(pageDataSymbol, pageData);
|
|
169
|
-
app.provide(pageFrontmatterSymbol, pageFrontmatter);
|
|
170
|
-
app.provide(pageHeadTitleSymbol, pageHeadTitle);
|
|
171
|
-
app.provide(pageHeadSymbol, pageHead);
|
|
172
|
-
app.provide(pageLangSymbol, pageLang);
|
|
173
|
-
app.provide(pageLayoutSymbol, pageLayout);
|
|
174
|
-
app.provide(routeLocaleSymbol, routeLocale);
|
|
175
|
-
app.provide(siteLocaleDataSymbol, siteLocaleData);
|
|
176
|
-
Object.defineProperties(app.config.globalProperties, {
|
|
177
|
-
$frontmatter: { get: () => pageFrontmatter.value },
|
|
178
|
-
$head: { get: () => pageHead.value },
|
|
179
|
-
$headTitle: { get: () => pageHeadTitle.value },
|
|
180
|
-
$lang: { get: () => pageLang.value },
|
|
181
|
-
$page: { get: () => pageData.value },
|
|
182
|
-
$routeLocale: { get: () => routeLocale.value },
|
|
183
|
-
$site: { get: () => siteData.value },
|
|
184
|
-
$siteLocale: { get: () => siteLocaleData.value },
|
|
185
|
-
$withBase: { get: () => withBase }
|
|
186
|
-
});
|
|
187
|
-
return {
|
|
136
|
+
const clientData = {
|
|
188
137
|
layouts,
|
|
189
138
|
pageData,
|
|
139
|
+
pageComponent,
|
|
190
140
|
pageFrontmatter,
|
|
191
141
|
pageHead,
|
|
192
142
|
pageHeadTitle,
|
|
193
143
|
pageLang,
|
|
194
144
|
pageLayout,
|
|
145
|
+
redirects,
|
|
195
146
|
routeLocale,
|
|
147
|
+
routePath,
|
|
148
|
+
routes,
|
|
196
149
|
siteData,
|
|
197
150
|
siteLocaleData
|
|
198
151
|
};
|
|
152
|
+
app.provide(clientDataSymbol, clientData);
|
|
153
|
+
Object.defineProperties(app.config.globalProperties, {
|
|
154
|
+
$frontmatter: { get: () => pageFrontmatter.value },
|
|
155
|
+
$head: { get: () => pageHead.value },
|
|
156
|
+
$headTitle: { get: () => pageHeadTitle.value },
|
|
157
|
+
$lang: { get: () => pageLang.value },
|
|
158
|
+
$page: { get: () => pageData.value },
|
|
159
|
+
$routeLocale: { get: () => routeLocale.value },
|
|
160
|
+
$site: { get: () => siteData.value },
|
|
161
|
+
$siteLocale: { get: () => siteLocaleData.value },
|
|
162
|
+
$withBase: { get: () => withBase }
|
|
163
|
+
});
|
|
164
|
+
return clientData;
|
|
199
165
|
};
|
|
200
166
|
|
|
201
167
|
// src/setupUpdateHead.ts
|
|
@@ -311,25 +277,24 @@ var createHeadElement = ([
|
|
|
311
277
|
var appCreator = __VUEPRESS_DEV__ ? createApp : createSSRApp;
|
|
312
278
|
var createVueApp = async () => {
|
|
313
279
|
const app = appCreator({
|
|
314
|
-
name: "
|
|
280
|
+
name: "Vuepress",
|
|
315
281
|
setup() {
|
|
316
282
|
setupUpdateHead();
|
|
317
283
|
for (const clientConfig of clientConfigs) {
|
|
318
284
|
clientConfig.setup?.();
|
|
319
285
|
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
];
|
|
286
|
+
const rootComponents = clientConfigs.flatMap(
|
|
287
|
+
({ rootComponents: rootComponents2 = [] }) => rootComponents2.map((component) => h(component))
|
|
288
|
+
);
|
|
289
|
+
const pageLayout = usePageLayout();
|
|
290
|
+
return () => [h(pageLayout.value), rootComponents];
|
|
326
291
|
}
|
|
327
292
|
});
|
|
328
293
|
const router = createVueRouter();
|
|
329
294
|
setupGlobalComponents(app);
|
|
330
295
|
const globalComputed = setupGlobalComputed(app, router, clientConfigs);
|
|
331
296
|
if (__VUEPRESS_DEV__ || __VUE_PROD_DEVTOOLS__) {
|
|
332
|
-
const { setupDevtools } = await import("./setupDevtools-
|
|
297
|
+
const { setupDevtools } = await import("./setupDevtools-H6KAGBNI.js");
|
|
333
298
|
setupDevtools(app, globalComputed);
|
|
334
299
|
}
|
|
335
300
|
for (const clientConfig of clientConfigs) {
|
|
@@ -0,0 +1,397 @@
|
|
|
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, currentPath) => {
|
|
64
|
+
const normalizedPath = normalizeRoutePath(path, currentPath);
|
|
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] || redirects.value[encodedPath] || normalizedPath;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// src/router/resolveRoute.ts
|
|
74
|
+
var resolveRoute = (path, currentPath) => {
|
|
75
|
+
const routePath = resolveRoutePath(path, currentPath);
|
|
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/router/index.ts
|
|
88
|
+
import { useRoute, useRouter } from "vue-router";
|
|
89
|
+
|
|
90
|
+
// src/components/RouteLink.ts
|
|
91
|
+
import { computed, defineComponent, h } from "vue";
|
|
92
|
+
import { useRoute as useRoute2, useRouter as useRouter2 } from "vue-router";
|
|
93
|
+
var guardEvent = (event) => {
|
|
94
|
+
if (event.metaKey || event.altKey || event.ctrlKey || event.shiftKey)
|
|
95
|
+
return;
|
|
96
|
+
if (event.defaultPrevented)
|
|
97
|
+
return;
|
|
98
|
+
if (event.button !== void 0 && event.button !== 0)
|
|
99
|
+
return;
|
|
100
|
+
if (event.currentTarget) {
|
|
101
|
+
const target = event.currentTarget.getAttribute("target");
|
|
102
|
+
if (target?.match(/\b_blank\b/i))
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
event.preventDefault();
|
|
106
|
+
return true;
|
|
107
|
+
};
|
|
108
|
+
var RouteLink = defineComponent({
|
|
109
|
+
name: "RouteLink",
|
|
110
|
+
props: {
|
|
111
|
+
/**
|
|
112
|
+
* The route path to link to
|
|
113
|
+
*/
|
|
114
|
+
to: {
|
|
115
|
+
type: String,
|
|
116
|
+
required: true
|
|
117
|
+
},
|
|
118
|
+
/**
|
|
119
|
+
* Whether the link is active to have an active class
|
|
120
|
+
*
|
|
121
|
+
* Notice that the active status is not automatically determined according to the current route.
|
|
122
|
+
*/
|
|
123
|
+
active: Boolean,
|
|
124
|
+
/**
|
|
125
|
+
* The class to add when the link is active
|
|
126
|
+
*/
|
|
127
|
+
activeClass: {
|
|
128
|
+
type: String,
|
|
129
|
+
default: "route-link-active"
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
slots: Object,
|
|
133
|
+
setup(props, { slots }) {
|
|
134
|
+
const router = useRouter2();
|
|
135
|
+
const route = useRoute2();
|
|
136
|
+
const path = computed(
|
|
137
|
+
() => props.to.startsWith("#") || props.to.startsWith("?") ? props.to : `${__VUEPRESS_BASE__}${resolveRoutePath(props.to, route.path).substring(1)}`
|
|
138
|
+
);
|
|
139
|
+
return () => h(
|
|
140
|
+
"a",
|
|
141
|
+
{
|
|
142
|
+
class: ["route-link", { [props.activeClass]: props.active }],
|
|
143
|
+
href: path.value,
|
|
144
|
+
onClick: (event = {}) => {
|
|
145
|
+
if (guardEvent(event)) {
|
|
146
|
+
router.push(props.to).catch();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
slots.default?.()
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
// src/components/AutoLink.ts
|
|
156
|
+
import { isLinkWithProtocol } from "@vuepress/shared";
|
|
157
|
+
import { computed as computed2, defineComponent as defineComponent2, h as h2, toRef } from "vue";
|
|
158
|
+
import { useRoute as useRoute3 } from "vue-router";
|
|
159
|
+
var AutoLink = defineComponent2({
|
|
160
|
+
name: "AutoLink",
|
|
161
|
+
props: {
|
|
162
|
+
config: {
|
|
163
|
+
type: Object,
|
|
164
|
+
required: true
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
slots: Object,
|
|
168
|
+
setup(props, { slots }) {
|
|
169
|
+
const config = toRef(props, "config");
|
|
170
|
+
const route = useRoute3();
|
|
171
|
+
const siteData = useSiteData();
|
|
172
|
+
const withProtocol = computed2(() => isLinkWithProtocol(config.value.link));
|
|
173
|
+
const linkTarget = computed2(
|
|
174
|
+
() => config.value.target || (withProtocol.value ? "_blank" : void 0)
|
|
175
|
+
);
|
|
176
|
+
const isBlankTarget = computed2(() => linkTarget.value === "_blank");
|
|
177
|
+
const isInternal = computed2(
|
|
178
|
+
() => !withProtocol.value && !isBlankTarget.value
|
|
179
|
+
);
|
|
180
|
+
const linkRel = computed2(
|
|
181
|
+
() => config.value.rel || (isBlankTarget.value ? "noopener noreferrer" : null)
|
|
182
|
+
);
|
|
183
|
+
const linkAriaLabel = computed2(
|
|
184
|
+
() => config.value.ariaLabel ?? config.value.text
|
|
185
|
+
);
|
|
186
|
+
const shouldBeActiveInSubpath = computed2(() => {
|
|
187
|
+
if (config.value.exact)
|
|
188
|
+
return false;
|
|
189
|
+
const localePaths = Object.keys(siteData.value.locales);
|
|
190
|
+
return localePaths.length ? (
|
|
191
|
+
// Check all the locales
|
|
192
|
+
localePaths.every((key) => key !== config.value.link)
|
|
193
|
+
) : (
|
|
194
|
+
// Check root
|
|
195
|
+
config.value.link !== "/"
|
|
196
|
+
);
|
|
197
|
+
});
|
|
198
|
+
const isActive = computed2(() => {
|
|
199
|
+
if (!isInternal.value)
|
|
200
|
+
return false;
|
|
201
|
+
if (config.value.activeMatch) {
|
|
202
|
+
return (config.value.activeMatch instanceof RegExp ? config.value.activeMatch : new RegExp(config.value.activeMatch, "u")).test(route.path);
|
|
203
|
+
}
|
|
204
|
+
if (shouldBeActiveInSubpath.value) {
|
|
205
|
+
return route.path.startsWith(config.value.link);
|
|
206
|
+
}
|
|
207
|
+
return route.path === config.value.link;
|
|
208
|
+
});
|
|
209
|
+
return () => {
|
|
210
|
+
const { before, after, default: defaultSlot } = slots;
|
|
211
|
+
const content = defaultSlot?.(config.value) || [
|
|
212
|
+
before?.(config.value),
|
|
213
|
+
config.value.text,
|
|
214
|
+
after?.(config.value)
|
|
215
|
+
];
|
|
216
|
+
return isInternal.value ? h2(
|
|
217
|
+
RouteLink,
|
|
218
|
+
{
|
|
219
|
+
"class": "auto-link",
|
|
220
|
+
"to": config.value.link,
|
|
221
|
+
"active": isActive.value,
|
|
222
|
+
"aria-label": linkAriaLabel.value
|
|
223
|
+
},
|
|
224
|
+
() => content
|
|
225
|
+
) : h2(
|
|
226
|
+
"a",
|
|
227
|
+
{
|
|
228
|
+
"class": "auto-link external-link",
|
|
229
|
+
"href": config.value.link,
|
|
230
|
+
"aria-label": linkAriaLabel.value,
|
|
231
|
+
"rel": linkRel.value,
|
|
232
|
+
"target": linkTarget.value
|
|
233
|
+
},
|
|
234
|
+
content
|
|
235
|
+
);
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
// src/components/ClientOnly.ts
|
|
241
|
+
import { defineComponent as defineComponent3, onMounted, ref } from "vue";
|
|
242
|
+
var ClientOnly = defineComponent3({
|
|
243
|
+
name: "ClientOnly",
|
|
244
|
+
setup(_, ctx) {
|
|
245
|
+
const isMounted = ref(false);
|
|
246
|
+
onMounted(() => {
|
|
247
|
+
isMounted.value = true;
|
|
248
|
+
});
|
|
249
|
+
return () => isMounted.value ? ctx.slots.default?.() : null;
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
// src/components/Content.ts
|
|
254
|
+
import { computed as computed3, defineAsyncComponent, defineComponent as defineComponent4, h as h3 } from "vue";
|
|
255
|
+
var Content = defineComponent4({
|
|
256
|
+
// eslint-disable-next-line vue/no-reserved-component-names
|
|
257
|
+
name: "Content",
|
|
258
|
+
props: {
|
|
259
|
+
path: {
|
|
260
|
+
type: String,
|
|
261
|
+
required: false,
|
|
262
|
+
default: ""
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
setup(props) {
|
|
266
|
+
const pageComponent = usePageComponent();
|
|
267
|
+
const ContentComponent = computed3(() => {
|
|
268
|
+
if (!props.path)
|
|
269
|
+
return pageComponent.value;
|
|
270
|
+
const route = resolveRoute(props.path);
|
|
271
|
+
return defineAsyncComponent(() => route.loader().then(({ comp }) => comp));
|
|
272
|
+
});
|
|
273
|
+
return () => h3(ContentComponent.value);
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
// src/resolvers.ts
|
|
278
|
+
import { dedupeHead, isString, resolveLocalePath } from "@vuepress/shared";
|
|
279
|
+
import { reactive } from "vue";
|
|
280
|
+
|
|
281
|
+
// src/constants.ts
|
|
282
|
+
var LAYOUT_NAME_DEFAULT = "Layout";
|
|
283
|
+
var LANG_DEFAULT = "en-US";
|
|
284
|
+
|
|
285
|
+
// src/resolvers.ts
|
|
286
|
+
var resolvers = reactive({
|
|
287
|
+
/**
|
|
288
|
+
* Resolve layouts component map
|
|
289
|
+
*/
|
|
290
|
+
resolveLayouts: (clientConfigs) => clientConfigs.reduce(
|
|
291
|
+
(prev, item) => ({
|
|
292
|
+
...prev,
|
|
293
|
+
...item.layouts
|
|
294
|
+
}),
|
|
295
|
+
{}
|
|
296
|
+
),
|
|
297
|
+
/**
|
|
298
|
+
* Merge the head config in frontmatter and site locale
|
|
299
|
+
*
|
|
300
|
+
* Frontmatter should take priority over site locale
|
|
301
|
+
*/
|
|
302
|
+
resolvePageHead: (pageHeadTitle, pageFrontmatter, siteLocaleDate) => {
|
|
303
|
+
const description = isString(pageFrontmatter.description) ? pageFrontmatter.description : siteLocaleDate.description;
|
|
304
|
+
const head = [
|
|
305
|
+
...Array.isArray(pageFrontmatter.head) ? pageFrontmatter.head : [],
|
|
306
|
+
...siteLocaleDate.head,
|
|
307
|
+
["title", {}, pageHeadTitle],
|
|
308
|
+
["meta", { name: "description", content: description }]
|
|
309
|
+
];
|
|
310
|
+
return dedupeHead(head);
|
|
311
|
+
},
|
|
312
|
+
/**
|
|
313
|
+
* Resolve the content of page head title
|
|
314
|
+
*
|
|
315
|
+
* It would be used as the content of the `<title>` tag
|
|
316
|
+
*/
|
|
317
|
+
resolvePageHeadTitle: (pageData, siteLocaleDate) => [pageData.title, siteLocaleDate.title].filter((item) => !!item).join(" | "),
|
|
318
|
+
/**
|
|
319
|
+
* Resolve page language from page data
|
|
320
|
+
*
|
|
321
|
+
* It would be used as the `lang` attribute of `<html>` tag
|
|
322
|
+
*/
|
|
323
|
+
resolvePageLang: (pageData, siteLocaleData) => pageData.lang || siteLocaleData.lang || LANG_DEFAULT,
|
|
324
|
+
/**
|
|
325
|
+
* Resolve layout component of current page
|
|
326
|
+
*/
|
|
327
|
+
resolvePageLayout: (pageData, layouts) => {
|
|
328
|
+
const layoutName = isString(pageData.frontmatter.layout) ? pageData.frontmatter.layout : LAYOUT_NAME_DEFAULT;
|
|
329
|
+
if (!layouts[layoutName]) {
|
|
330
|
+
throw new Error(`[vuepress] Cannot resolve layout: ${layoutName}`);
|
|
331
|
+
}
|
|
332
|
+
return layouts[layoutName];
|
|
333
|
+
},
|
|
334
|
+
/**
|
|
335
|
+
* Resolve locale path according to route path and locales config
|
|
336
|
+
*/
|
|
337
|
+
resolveRouteLocale: (locales, routePath) => resolveLocalePath(locales, routePath),
|
|
338
|
+
/**
|
|
339
|
+
* Resolve site data for specific locale
|
|
340
|
+
*
|
|
341
|
+
* It would merge the locales fields to the root fields
|
|
342
|
+
*/
|
|
343
|
+
resolveSiteLocaleData: ({ base, locales, ...siteData }, routeLocale) => ({
|
|
344
|
+
...siteData,
|
|
345
|
+
...locales[routeLocale],
|
|
346
|
+
head: [
|
|
347
|
+
// when merging head, the locales head should be placed before root head
|
|
348
|
+
// to get higher priority
|
|
349
|
+
...locales[routeLocale]?.head ?? [],
|
|
350
|
+
...siteData.head ?? []
|
|
351
|
+
]
|
|
352
|
+
})
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
// src/utils/defineClientConfig.ts
|
|
356
|
+
var defineClientConfig = (clientConfig = {}) => clientConfig;
|
|
357
|
+
|
|
358
|
+
// src/utils/withBase.ts
|
|
359
|
+
import { isLinkHttp, removeLeadingSlash } from "@vuepress/shared";
|
|
360
|
+
var withBase = (url) => {
|
|
361
|
+
if (isLinkHttp(url))
|
|
362
|
+
return url;
|
|
363
|
+
return `${__VUEPRESS_BASE__}${removeLeadingSlash(url)}`;
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
export {
|
|
367
|
+
clientDataSymbol,
|
|
368
|
+
useClientData,
|
|
369
|
+
useLayouts,
|
|
370
|
+
usePageComponent,
|
|
371
|
+
usePageData,
|
|
372
|
+
usePageFrontmatter,
|
|
373
|
+
usePageHead,
|
|
374
|
+
usePageLang,
|
|
375
|
+
usePageLayout,
|
|
376
|
+
useRedirects,
|
|
377
|
+
useRouteLocale,
|
|
378
|
+
useRoutePath,
|
|
379
|
+
useRoutes,
|
|
380
|
+
useSiteData,
|
|
381
|
+
useSiteLocaleData,
|
|
382
|
+
updateHeadSymbol,
|
|
383
|
+
useUpdateHead,
|
|
384
|
+
redirects,
|
|
385
|
+
routes,
|
|
386
|
+
resolveRoutePath,
|
|
387
|
+
resolveRoute,
|
|
388
|
+
useRoute,
|
|
389
|
+
useRouter,
|
|
390
|
+
RouteLink,
|
|
391
|
+
AutoLink,
|
|
392
|
+
ClientOnly,
|
|
393
|
+
Content,
|
|
394
|
+
resolvers,
|
|
395
|
+
defineClientConfig,
|
|
396
|
+
withBase
|
|
397
|
+
};
|