valaxy 1.2.2 → 1.3.0
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/bin/valaxy.mjs +1 -5
- package/client/components/ValaxyDecrypt.vue +6 -25
- package/client/components/ValaxyDynamicComponent.vue +13 -34
- package/client/components/ValaxyFootnoteTooltip.vue +140 -11
- package/client/composables/app/index.ts +1 -0
- package/client/composables/app/usePageSeo.ts +40 -0
- package/client/composables/app/useValaxyApp.ts +24 -23
- package/client/composables/app/useValaxyHead.ts +5 -12
- package/client/composables/dark.ts +8 -1
- package/client/composables/post/filter.ts +1 -1
- package/client/composables/post/index.ts +4 -4
- package/client/composables/search/index.ts +2 -0
- package/client/composables/search/package.json +4 -0
- package/client/composables/search/useFuseSearch.ts +1 -1
- package/client/composables/widgets/backToTop.ts +30 -6
- package/client/main.ts +6 -6
- package/client/runtime/ValaxyRuntimeTemplate.vue +26 -0
- package/client/setup/main.ts +0 -2
- package/client/shims.d.ts +4 -0
- package/client/stores/router.ts +12 -0
- package/client/stores/site.ts +5 -50
- package/client/utils/index.ts +1 -0
- package/client/utils/seo.ts +79 -0
- package/client/utils/time.ts +7 -4
- package/dist/node/cli/index.mjs +2 -3
- package/dist/node/index.d.mts +295 -48
- package/dist/node/index.mjs +2 -3
- package/dist/shared/{valaxy.BTmQYjWn.mjs → valaxy.BrBGPvyF.mjs} +1250 -210
- package/dist/shared/{valaxy.EzGcrVef.d.mts → valaxy.Jqi53gnQ.d.mts} +42 -15
- package/dist/types/index.d.mts +2 -2
- package/package.json +4 -5
- package/shared/index.ts +2 -0
- package/shared/page-policy.ts +123 -0
- package/shared/seo.ts +182 -0
- package/types/config.ts +39 -17
- package/types/vue-router.d.ts +4 -0
- package/vendor/README.md +4 -4
- package/client/components/footnote/FootnotePopover.vue +0 -146
- package/client/components/footnote/LegacyFootnoteTooltip.vue +0 -25
- package/client/modules/floating-vue.ts +0 -11
- package/vendor/ensure-gray-matter.d.ts +0 -1
- package/vendor/ensure-gray-matter.mjs +0 -23
- package/vendor/redirect-gray-matter.mjs +0 -30
|
@@ -10,13 +10,12 @@ import fs from 'fs-extra';
|
|
|
10
10
|
import { glob, globSync } from 'tinyglobby';
|
|
11
11
|
import * as yaml from 'js-yaml';
|
|
12
12
|
import { dump, load, CORE_SCHEMA } from 'js-yaml';
|
|
13
|
-
import { isFunction, ensurePrefix, slash as slash$1, uniq, ensureSuffix, isObject } from '@antfu/utils';
|
|
13
|
+
import { isFunction, ensurePrefix, slash as slash$1, uniq as uniq$1, ensureSuffix, isObject } from '@antfu/utils';
|
|
14
14
|
import _debug from 'debug';
|
|
15
15
|
import path$1, { resolve as resolve$1, relative, isAbsolute, normalize, join as join$1, basename as basename$1, dirname as dirname$1 } from 'pathe';
|
|
16
16
|
import defu, { createDefu } from 'defu';
|
|
17
|
-
import { mergeConfig, loadConfigFromFile as loadConfigFromFile$1, searchForWorkspaceRoot, build as build$3, createServer as createServer$1 } from 'vite';
|
|
17
|
+
import { mergeConfig, loadConfigFromFile as loadConfigFromFile$1, normalizePath, searchForWorkspaceRoot, build as build$3, createServer as createServer$1 } from 'vite';
|
|
18
18
|
import { webcrypto, createHash } from 'node:crypto';
|
|
19
|
-
import { options } from 'floating-vue';
|
|
20
19
|
import { loadConfig } from 'define-config-ts';
|
|
21
20
|
import ora from 'ora';
|
|
22
21
|
import { Buffer as Buffer$1 } from 'node:buffer';
|
|
@@ -26,7 +25,7 @@ import { resolveGlobal } from 'resolve-global';
|
|
|
26
25
|
import { normalizeRepositoryUrl } from '@valaxyjs/utils';
|
|
27
26
|
import { existsSync, readFileSync, realpathSync, statSync } from 'node:fs';
|
|
28
27
|
import picomatch from 'picomatch';
|
|
29
|
-
import { readFile, mkdir, writeFile, realpath, rm, stat } from 'node:fs/promises';
|
|
28
|
+
import { readFile, mkdir, writeFile, realpath, copyFile, access, constants, rm, stat } from 'node:fs/promises';
|
|
30
29
|
import dayjs from 'dayjs';
|
|
31
30
|
import { Feed } from 'feed';
|
|
32
31
|
import { createMarkdownExit } from 'markdown-exit';
|
|
@@ -36,7 +35,7 @@ import { Unhead } from '@unhead/bundler/vite';
|
|
|
36
35
|
import { groupIconMdPlugin, groupIconVitePlugin } from 'vitepress-plugin-group-icons';
|
|
37
36
|
import { isPackageExists } from 'local-pkg';
|
|
38
37
|
import chokidar from 'chokidar';
|
|
39
|
-
import { createUnplugin } from 'unplugin';
|
|
38
|
+
import { createUnplugin, createVitePlugin } from 'unplugin';
|
|
40
39
|
import { createFilter } from 'unplugin-utils';
|
|
41
40
|
import { createDebug } from 'obug';
|
|
42
41
|
import MagicString from 'magic-string';
|
|
@@ -58,14 +57,14 @@ import { URL as URL$1, pathToFileURL } from 'node:url';
|
|
|
58
57
|
import container from 'markdown-it-container';
|
|
59
58
|
import katex from 'katex';
|
|
60
59
|
import 'katex/contrib/mhchem';
|
|
61
|
-
import {
|
|
60
|
+
import { createRequire } from 'node:module';
|
|
62
61
|
import { createJiti } from 'jiti';
|
|
63
62
|
import { transformerDirectives, transformerVariantGroup, presetWind4, presetAttributify, presetIcons, presetTypography } from 'unocss';
|
|
64
63
|
import { convert } from 'html-to-text';
|
|
65
64
|
import VueRouter from 'vue-router/vite';
|
|
66
65
|
import generateSitemap from 'vite-ssg-sitemap';
|
|
67
66
|
import { renderSSRHead } from '@unhead/vue/server';
|
|
68
|
-
import { createRoutesContext, resolveOptions as resolveOptions$
|
|
67
|
+
import { createRoutesContext, resolveOptions as resolveOptions$3 } from 'vue-router/unplugin';
|
|
69
68
|
import { execSync, exec } from 'node:child_process';
|
|
70
69
|
import { intro, confirm, isCancel, cancel, select, outro } from '@clack/prompts';
|
|
71
70
|
import net from 'node:net';
|
|
@@ -73,7 +72,7 @@ import * as readline from 'node:readline';
|
|
|
73
72
|
import qrcode from 'qrcode';
|
|
74
73
|
import ejs from 'ejs';
|
|
75
74
|
|
|
76
|
-
const version = "1.
|
|
75
|
+
const version = "1.3.0";
|
|
77
76
|
|
|
78
77
|
const GLOBAL_STATE = {
|
|
79
78
|
valaxyApp: void 0,
|
|
@@ -182,6 +181,176 @@ function nodeT(key, lang) {
|
|
|
182
181
|
return result || "";
|
|
183
182
|
}
|
|
184
183
|
|
|
184
|
+
function normalizePagePath(filePath) {
|
|
185
|
+
return filePath.replace(/\\/g, "/").replace(/^\.\//, "");
|
|
186
|
+
}
|
|
187
|
+
function relativePagePath(filePath, userRoot) {
|
|
188
|
+
const normalized = normalizePagePath(filePath);
|
|
189
|
+
if (userRoot) {
|
|
190
|
+
const root = normalizePagePath(userRoot).replace(/\/$/, "");
|
|
191
|
+
const prefixes = [`${root}/pages/`, `${root}/.valaxy/content/pages/`];
|
|
192
|
+
for (const prefix of prefixes) {
|
|
193
|
+
if (normalized.startsWith(prefix))
|
|
194
|
+
return normalized.slice(prefix.length);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
const markers = ["/.valaxy/content/pages/", "/pages/"];
|
|
198
|
+
for (const marker of markers) {
|
|
199
|
+
const index = normalized.lastIndexOf(marker);
|
|
200
|
+
if (index >= 0)
|
|
201
|
+
return normalized.slice(index + marker.length);
|
|
202
|
+
}
|
|
203
|
+
if (normalized.startsWith("pages/"))
|
|
204
|
+
return normalized.slice("pages/".length);
|
|
205
|
+
}
|
|
206
|
+
function isUnderscorePage(relativePath) {
|
|
207
|
+
return normalizePagePath(relativePath).split("/").some((segment) => segment.startsWith("_"));
|
|
208
|
+
}
|
|
209
|
+
function isReadmePage(relativePath) {
|
|
210
|
+
const base = normalizePagePath(relativePath).split("/").pop() || "";
|
|
211
|
+
return /^readme\.md$/i.test(base);
|
|
212
|
+
}
|
|
213
|
+
function isUnpublishedPage(relativePath, publishing = {}) {
|
|
214
|
+
if (!publishing.underscore && isUnderscorePage(relativePath))
|
|
215
|
+
return true;
|
|
216
|
+
if (!publishing.readme && isReadmePage(relativePath))
|
|
217
|
+
return true;
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
function pageExcludeGlobs(publishing = {}) {
|
|
221
|
+
const globs = [];
|
|
222
|
+
if (!publishing.underscore)
|
|
223
|
+
globs.push("**/_*/**", "**/_*");
|
|
224
|
+
if (!publishing.readme)
|
|
225
|
+
globs.push("**/[Rr][Ee][Aa][Dd][Mm][Ee].[Mm][Dd]");
|
|
226
|
+
return globs;
|
|
227
|
+
}
|
|
228
|
+
function normalizeExcludeGlobs(exclude) {
|
|
229
|
+
if (typeof exclude === "string")
|
|
230
|
+
return [exclude];
|
|
231
|
+
if (Array.isArray(exclude))
|
|
232
|
+
return exclude.filter((item) => typeof item === "string");
|
|
233
|
+
return [];
|
|
234
|
+
}
|
|
235
|
+
function mergePageExcludes(publishing, userExclude) {
|
|
236
|
+
const defaults = pageExcludeGlobs(publishing);
|
|
237
|
+
if (typeof userExclude === "function")
|
|
238
|
+
return userExclude(defaults);
|
|
239
|
+
return [...defaults, ...normalizeExcludeGlobs(userExclude)];
|
|
240
|
+
}
|
|
241
|
+
function notFoundSitemapPaths(routes) {
|
|
242
|
+
const paths = /* @__PURE__ */ new Set();
|
|
243
|
+
for (const route of routes) {
|
|
244
|
+
const path = route.length > 1 && route.endsWith("/") ? route.slice(0, -1) : route;
|
|
245
|
+
if (path === "/404" || path.endsWith("/404"))
|
|
246
|
+
paths.add(path);
|
|
247
|
+
}
|
|
248
|
+
return [...paths];
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function publicAuthor(author) {
|
|
252
|
+
const result = {};
|
|
253
|
+
const name = author?.name?.trim();
|
|
254
|
+
const email = author?.email?.trim();
|
|
255
|
+
const link = author?.link?.trim();
|
|
256
|
+
if (name)
|
|
257
|
+
result.name = name;
|
|
258
|
+
if (email)
|
|
259
|
+
result.email = email;
|
|
260
|
+
if (link)
|
|
261
|
+
result.link = link;
|
|
262
|
+
return result;
|
|
263
|
+
}
|
|
264
|
+
const SHARE_IMAGE = /\.(?:avif|bmp|gif|ico|jpe?g|png|svg|webp)$/i;
|
|
265
|
+
function pickShareImage(candidates) {
|
|
266
|
+
for (const candidate of candidates) {
|
|
267
|
+
const value = typeof candidate === "string" ? candidate.trim() : "";
|
|
268
|
+
if (!value || Array.from(value).some((char) => char.charCodeAt(0) < 32 || char.charCodeAt(0) === 127))
|
|
269
|
+
continue;
|
|
270
|
+
const url = value.startsWith("<") ? value.match(/^<([^>]+)>/)?.[1] : value.replace(/\s+(?:"[^"]*"|'[^']*'|\([^)]*\))$/, "");
|
|
271
|
+
if (!url || url.includes("\\"))
|
|
272
|
+
continue;
|
|
273
|
+
const pathname = url.split(/[?#]/)[0];
|
|
274
|
+
if (/\.vue$/i.test(pathname) || /^[a-z][a-z\d+.-]*:/i.test(url) && !/^https?:\/\//i.test(url))
|
|
275
|
+
continue;
|
|
276
|
+
if (/^(?:https?:)?\/\//i.test(url)) {
|
|
277
|
+
try {
|
|
278
|
+
if (new URL(url, "https://valaxy.local").hostname)
|
|
279
|
+
return url;
|
|
280
|
+
} catch {
|
|
281
|
+
}
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
if (/^(?:\/|\.\.?\/)/.test(url) || pathname.includes("/") || SHARE_IMAGE.test(pathname))
|
|
285
|
+
return url;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
function pickPageShareImage(frontmatter) {
|
|
289
|
+
return pickShareImage([frontmatter.ogImage, frontmatter.image, frontmatter.cover, frontmatter.firstImage]);
|
|
290
|
+
}
|
|
291
|
+
function stripEncryptedContent(markdown) {
|
|
292
|
+
return markdown.replace(/<!--\s*valaxy-encrypt-start:[\s\S]*?(?:<!-- valaxy-encrypt-end -->|$)/g, "\n");
|
|
293
|
+
}
|
|
294
|
+
function plainSeoDescription(markdown, maxLength = 200) {
|
|
295
|
+
if (!markdown || maxLength <= 0)
|
|
296
|
+
return "";
|
|
297
|
+
let text = stripEncryptedContent(markdown).replace(/\r\n/g, "\n");
|
|
298
|
+
text = text.replace(/```[\s\S]*?```/g, "\n");
|
|
299
|
+
text = text.replace(/~~~[\s\S]*?~~~/g, "\n");
|
|
300
|
+
text = text.replace(/```[\s\S]*$/g, "\n");
|
|
301
|
+
text = text.replace(/~~~[\s\S]*$/g, "\n");
|
|
302
|
+
text = text.replace(/<!--[\s\S]*?-->/g, "\n");
|
|
303
|
+
text = text.replace(/<script[\s\S]*?<\/script>/gi, "\n");
|
|
304
|
+
text = text.replace(/<style[\s\S]*?<\/style>/gi, "\n");
|
|
305
|
+
text = text.replace(/!\[[^\]]*\]\([^)]*\)/g, "\n");
|
|
306
|
+
text = text.replace(/<[^>]+>/g, " ");
|
|
307
|
+
const paragraphs = [];
|
|
308
|
+
for (const block of text.split(/\n\s*\n/)) {
|
|
309
|
+
const lines = block.split("\n").map((line) => line.trim()).filter(Boolean);
|
|
310
|
+
const prose = lines.filter(
|
|
311
|
+
(line) => !/^#{1,6}\s/.test(line) && !/^```|^~~~/.test(line) && !/^(?:-{3,}|\*{3,}|_{3,})$/.test(line) && !line.startsWith(":::") && !/^(?:import|export)\s/.test(line)
|
|
312
|
+
);
|
|
313
|
+
const paragraph = prose.map(stripInlineMarkdown).join(" ").replace(/\s+/g, " ").trim();
|
|
314
|
+
if (!paragraph)
|
|
315
|
+
continue;
|
|
316
|
+
paragraphs.push(paragraph);
|
|
317
|
+
if (paragraphs.join(" ").length >= maxLength)
|
|
318
|
+
break;
|
|
319
|
+
}
|
|
320
|
+
const combined = paragraphs.join(" ").replace(/\s+/g, " ").trim();
|
|
321
|
+
if (!combined || combined.length <= maxLength)
|
|
322
|
+
return combined;
|
|
323
|
+
const slice = combined.slice(0, maxLength + 1);
|
|
324
|
+
const windowStart = Math.floor(maxLength * 0.6);
|
|
325
|
+
const space = slice.lastIndexOf(" ");
|
|
326
|
+
const end = space >= windowStart ? space : maxLength;
|
|
327
|
+
const trimmed = combined.slice(0, end).replace(/[\s,;:]+$/u, "").trim();
|
|
328
|
+
return trimmed ? `${trimmed}\u2026` : "";
|
|
329
|
+
}
|
|
330
|
+
function stripInlineMarkdown(line) {
|
|
331
|
+
const literals = [];
|
|
332
|
+
const protect = (value) => `\0${literals.push(value) - 1}\0`;
|
|
333
|
+
let text = line.replace(/(`+)(.*?)\1/g, (_, _fence, code) => protect(code)).replace(/\\([\\`*_~[\]{}()#+\-.!|>])/g, (_, char) => protect(char)).replace(/\[([^\]]+)\]\([^)]*\)/g, "$1").replace(/\[([^\]]+)\]\[[^\]]*\]/g, "$1");
|
|
334
|
+
for (let depth = 0; depth < 3; depth++) {
|
|
335
|
+
text = text.replace(/(?<![\p{L}\p{N}_])(_{1,3})(?=\S)(.+?\S|\S)\1(?![\p{L}\p{N}_])/gu, "$2").replace(/(?<!\*)(\*{1,3})(?=\S)(.+?\S|\S)\1(?!\*)/g, "$2").replace(/~~(?=\S)(.+?\S|\S)~~/g, "$1");
|
|
336
|
+
}
|
|
337
|
+
return text.replace(/^>\s?/, "").replace(/^[-*+]\s+/, "").replace(/^\d+\.\s+/, "").replace(/\|/g, " ").replace(/\0(\d+)\0/g, (_, index) => literals[Number(index)]);
|
|
338
|
+
}
|
|
339
|
+
function extractMarkdownImage(code) {
|
|
340
|
+
const withoutFence = stripEncryptedContent(code).replace(/```[\s\S]*?```/g, "").replace(/~~~[\s\S]*?~~~/g, "");
|
|
341
|
+
const markdown = withoutFence.match(/!\[[^\]]*\]\(\s*<?([^\s)>]+)>?/);
|
|
342
|
+
if (markdown)
|
|
343
|
+
return markdown[1];
|
|
344
|
+
const html = withoutFence.match(/<img\s[^>]*?\bsrc=(?:"([^"]+)"|'([^']+)')/i);
|
|
345
|
+
return (html?.[1] || html?.[2])?.replace(/&(amp|lt|gt|quot|apos|#(?:x[\da-f]+|\d+));/gi, (entity, name) => {
|
|
346
|
+
if (name.startsWith("#")) {
|
|
347
|
+
const value = name[1].toLowerCase() === "x" ? Number.parseInt(name.slice(2), 16) : Number.parseInt(name.slice(1), 10);
|
|
348
|
+
return value > 0 && value <= 1114111 ? String.fromCodePoint(value) : entity;
|
|
349
|
+
}
|
|
350
|
+
return { amp: "&", lt: "<", gt: ">", quot: '"', apos: "'" }[name.toLowerCase()];
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
|
|
185
354
|
function commonOptions(args) {
|
|
186
355
|
return args.positional("root", {
|
|
187
356
|
default: ".",
|
|
@@ -190,14 +359,49 @@ function commonOptions(args) {
|
|
|
190
359
|
});
|
|
191
360
|
}
|
|
192
361
|
|
|
362
|
+
const EXCERPT_SEPARATOR = "<!-- more -->";
|
|
363
|
+
const PATHNAME_PROTOCOL_RE = /^pathname:\/\//;
|
|
364
|
+
const ALL_ROUTE = "/:all(.*)*";
|
|
365
|
+
const customElements = /* @__PURE__ */ new Set([
|
|
366
|
+
// katex (MathML elements)
|
|
367
|
+
"annotation",
|
|
368
|
+
"math",
|
|
369
|
+
"menclose",
|
|
370
|
+
"mfrac",
|
|
371
|
+
"mglyph",
|
|
372
|
+
"mi",
|
|
373
|
+
"mlabeledtr",
|
|
374
|
+
"mn",
|
|
375
|
+
"mo",
|
|
376
|
+
"mover",
|
|
377
|
+
"mpadded",
|
|
378
|
+
"mphantom",
|
|
379
|
+
"mroot",
|
|
380
|
+
"mrow",
|
|
381
|
+
"mspace",
|
|
382
|
+
"msqrt",
|
|
383
|
+
"mstyle",
|
|
384
|
+
"msub",
|
|
385
|
+
"msubsup",
|
|
386
|
+
"msup",
|
|
387
|
+
"mtable",
|
|
388
|
+
"mtd",
|
|
389
|
+
"mtext",
|
|
390
|
+
"mtr",
|
|
391
|
+
"munder",
|
|
392
|
+
"munderover",
|
|
393
|
+
"semantics",
|
|
394
|
+
// mathjax (SVG container element)
|
|
395
|
+
"mjx-container",
|
|
396
|
+
"mjx-assistive-mml"
|
|
397
|
+
]);
|
|
398
|
+
const defaultViteConfig = {};
|
|
399
|
+
|
|
193
400
|
function escapeRegExp(str) {
|
|
194
401
|
return str.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
|
|
195
402
|
}
|
|
196
|
-
function getRolldownOutputOptions(
|
|
403
|
+
function getRolldownOutputOptions() {
|
|
197
404
|
const assetsDir = "assets";
|
|
198
|
-
const escapedThemeRoot = escapeRegExp(
|
|
199
|
-
options.themeRoot.replace(/\\/g, "/")
|
|
200
|
-
);
|
|
201
405
|
const outputOptions = {
|
|
202
406
|
assetFileNames: `${assetsDir}/[name].[hash].[ext]`,
|
|
203
407
|
entryFileNames: `${assetsDir}/[name].[hash].js`,
|
|
@@ -246,13 +450,9 @@ function getRolldownOutputOptions(options) {
|
|
|
246
450
|
name: "chunks/@vueuse/motion",
|
|
247
451
|
test: /[\\/]@vueuse[\\/]motion[\\/]/,
|
|
248
452
|
priority: 20
|
|
249
|
-
},
|
|
250
|
-
// Theme code → theme chunk
|
|
251
|
-
{
|
|
252
|
-
name: "theme",
|
|
253
|
-
test: new RegExp(escapedThemeRoot),
|
|
254
|
-
priority: 10
|
|
255
453
|
}
|
|
454
|
+
// Leave theme modules to automatic splitting so dynamic imports keep
|
|
455
|
+
// their boundaries (search providers, comments and optional effects).
|
|
256
456
|
]
|
|
257
457
|
}
|
|
258
458
|
};
|
|
@@ -310,8 +510,9 @@ const defaultSiteConfig = {
|
|
|
310
510
|
subtitle: "Next Generation Static Blog Framework.",
|
|
311
511
|
author: {
|
|
312
512
|
avatar: "https://valaxy.site/valaxy-logo.png",
|
|
313
|
-
|
|
314
|
-
|
|
513
|
+
// Empty so a site that only sets a name does not publish Valaxy's address.
|
|
514
|
+
email: "",
|
|
515
|
+
link: "",
|
|
315
516
|
name: "VALAXY Developer",
|
|
316
517
|
status: {
|
|
317
518
|
emoji: "\u{1F30C}",
|
|
@@ -354,6 +555,11 @@ const defaultSiteConfig = {
|
|
|
354
555
|
auto: false,
|
|
355
556
|
length: 200
|
|
356
557
|
},
|
|
558
|
+
publishing: {
|
|
559
|
+
drafts: false,
|
|
560
|
+
underscore: false,
|
|
561
|
+
readme: false
|
|
562
|
+
},
|
|
357
563
|
frontmatter: {
|
|
358
564
|
time_warning: 180 * 24 * 60 * 60 * 1e3
|
|
359
565
|
},
|
|
@@ -369,10 +575,6 @@ const defaultSiteConfig = {
|
|
|
369
575
|
enable: false,
|
|
370
576
|
options: {}
|
|
371
577
|
},
|
|
372
|
-
floatingVue: options,
|
|
373
|
-
footnote: {
|
|
374
|
-
preview: "reka"
|
|
375
|
-
},
|
|
376
578
|
statistics: {
|
|
377
579
|
enable: false,
|
|
378
580
|
readTime: {
|
|
@@ -404,13 +606,6 @@ const defaultSiteConfig = {
|
|
|
404
606
|
function defineSiteConfig(config) {
|
|
405
607
|
return config;
|
|
406
608
|
}
|
|
407
|
-
function resolveFootnoteConfig(config = {}) {
|
|
408
|
-
const preview = config.footnote?.preview;
|
|
409
|
-
if (config.floatingVue != null) {
|
|
410
|
-
consola.warn(preview === "reka" ? "[Valaxy] siteConfig.floatingVue only configures legacy Floating Vue APIs; Reka footnotes use .va-footnote-popover styles." : "[Valaxy] siteConfig.floatingVue is deprecated for footnotes. Keeping the legacy preview; migrate with footnote: { preview: 'reka' }. See https://valaxy.site/guide/markdown#footnote-preview");
|
|
411
|
-
}
|
|
412
|
-
return { preview: preview ?? (config.floatingVue != null ? "floating-vue" : "reka") };
|
|
413
|
-
}
|
|
414
609
|
async function resolveSiteConfigFromRoot(root) {
|
|
415
610
|
return loadConfigFromFile("site", {
|
|
416
611
|
cwd: root
|
|
@@ -491,7 +686,7 @@ const defaultValaxyConfig = {
|
|
|
491
686
|
}
|
|
492
687
|
},
|
|
493
688
|
vue: {
|
|
494
|
-
browserTemplateCompilation:
|
|
689
|
+
browserTemplateCompilation: "lazy"
|
|
495
690
|
},
|
|
496
691
|
devtools: true,
|
|
497
692
|
mcp: false
|
|
@@ -876,7 +1071,7 @@ async function processValaxyOptions(valaxyOptions, valaxyConfig) {
|
|
|
876
1071
|
consola.debug(` \u251C\u2500 resolveAddonsConfig: ${resolveAddonsTimer()}`);
|
|
877
1072
|
const mergeTimer = countPerformanceTime();
|
|
878
1073
|
valaxyConfig = mergeValaxyConfig(valaxyConfig, addonsValaxyConfig);
|
|
879
|
-
const rolldownOutputOptions = getRolldownOutputOptions(
|
|
1074
|
+
const rolldownOutputOptions = getRolldownOutputOptions();
|
|
880
1075
|
consola.debug(` \u251C\u2500 mergeValaxyConfig + getRolldownOutputOptions: ${mergeTimer()}`);
|
|
881
1076
|
const buildConfig = defaultValaxyConfig.vite.build ??= {};
|
|
882
1077
|
buildConfig.rolldownOptions = {
|
|
@@ -895,7 +1090,6 @@ async function processValaxyOptions(valaxyOptions, valaxyConfig) {
|
|
|
895
1090
|
}
|
|
896
1091
|
};
|
|
897
1092
|
const config = replaceArrMerge(valaxyConfig, defaultValaxyConfig);
|
|
898
|
-
config.siteConfig.footnote = resolveFootnoteConfig(valaxyConfig.siteConfig);
|
|
899
1093
|
valaxyOptions.config = {
|
|
900
1094
|
...config,
|
|
901
1095
|
runtimeConfig: {
|
|
@@ -913,7 +1107,7 @@ async function processValaxyOptions(valaxyOptions, valaxyConfig) {
|
|
|
913
1107
|
const addonRoots = addons.map(({ root }) => root);
|
|
914
1108
|
const addonNames = addons.map(({ name }) => name);
|
|
915
1109
|
valaxyOptions.addonRoots = addonRoots;
|
|
916
|
-
valaxyOptions.roots = uniq([clientRoot, themeRoot, ...addonRoots, userRoot]);
|
|
1110
|
+
valaxyOptions.roots = uniq$1([clientRoot, themeRoot, ...addonRoots, userRoot]);
|
|
917
1111
|
const resolvedBuild = valaxyOptions.config.vite.build ??= {};
|
|
918
1112
|
const rawExternal = resolvedBuild.rolldownOptions?.external ?? resolvedBuild.rollupOptions?.external ?? [];
|
|
919
1113
|
const external = Array.isArray(rawExternal) ? rawExternal.filter((e) => typeof e === "string") : [];
|
|
@@ -926,7 +1120,7 @@ async function processValaxyOptions(valaxyOptions, valaxyConfig) {
|
|
|
926
1120
|
consola.debug(` \u2514\u2500 processSiteConfig: ${siteConfigTimer()}`);
|
|
927
1121
|
return valaxyOptions;
|
|
928
1122
|
}
|
|
929
|
-
async function resolveOptions$
|
|
1123
|
+
async function resolveOptions$2(options = { userRoot: process.cwd() }, mode = "dev") {
|
|
930
1124
|
const pkgRoot = dirname(await resolveImportPath("valaxy/package.json", true));
|
|
931
1125
|
const clientRoot = resolve$1(pkgRoot, "client");
|
|
932
1126
|
const userRoot = resolve$1(options.userRoot || process.cwd());
|
|
@@ -977,7 +1171,7 @@ async function resolveOptions$1(options = { userRoot: process.cwd() }, mode = "d
|
|
|
977
1171
|
configFile: configFile || "",
|
|
978
1172
|
siteConfigFile: siteConfigFile || "",
|
|
979
1173
|
themeConfigFile: themeConfigFile || "",
|
|
980
|
-
pages: pages.sort(),
|
|
1174
|
+
pages: pages.sort().filter((page) => !isUnpublishedPage(page, userValaxyConfig?.siteConfig?.publishing)),
|
|
981
1175
|
addons: [],
|
|
982
1176
|
redirects,
|
|
983
1177
|
env: {
|
|
@@ -1003,44 +1197,6 @@ async function resolveThemeValaxyConfig(options) {
|
|
|
1003
1197
|
return themeValaxyConfig;
|
|
1004
1198
|
}
|
|
1005
1199
|
|
|
1006
|
-
const EXCERPT_SEPARATOR = "<!-- more -->";
|
|
1007
|
-
const PATHNAME_PROTOCOL_RE = /^pathname:\/\//;
|
|
1008
|
-
const ALL_ROUTE = "/:all(.*)*";
|
|
1009
|
-
const customElements = /* @__PURE__ */ new Set([
|
|
1010
|
-
// katex (MathML elements)
|
|
1011
|
-
"annotation",
|
|
1012
|
-
"math",
|
|
1013
|
-
"menclose",
|
|
1014
|
-
"mfrac",
|
|
1015
|
-
"mglyph",
|
|
1016
|
-
"mi",
|
|
1017
|
-
"mlabeledtr",
|
|
1018
|
-
"mn",
|
|
1019
|
-
"mo",
|
|
1020
|
-
"mover",
|
|
1021
|
-
"mpadded",
|
|
1022
|
-
"mphantom",
|
|
1023
|
-
"mroot",
|
|
1024
|
-
"mrow",
|
|
1025
|
-
"mspace",
|
|
1026
|
-
"msqrt",
|
|
1027
|
-
"mstyle",
|
|
1028
|
-
"msub",
|
|
1029
|
-
"msubsup",
|
|
1030
|
-
"msup",
|
|
1031
|
-
"mtable",
|
|
1032
|
-
"mtd",
|
|
1033
|
-
"mtext",
|
|
1034
|
-
"mtr",
|
|
1035
|
-
"munder",
|
|
1036
|
-
"munderover",
|
|
1037
|
-
"semantics",
|
|
1038
|
-
// mathjax (SVG container element)
|
|
1039
|
-
"mjx-container",
|
|
1040
|
-
"mjx-assistive-mml"
|
|
1041
|
-
]);
|
|
1042
|
-
const defaultViteConfig = {};
|
|
1043
|
-
|
|
1044
1200
|
const matterOptions = {
|
|
1045
1201
|
excerpt_separator: EXCERPT_SEPARATOR,
|
|
1046
1202
|
engines: {
|
|
@@ -1132,15 +1288,21 @@ async function generateFuseList(options) {
|
|
|
1132
1288
|
const posts = [];
|
|
1133
1289
|
for await (const i of files) {
|
|
1134
1290
|
const raw = fs.readFileSync(i, "utf-8");
|
|
1135
|
-
const { data,
|
|
1136
|
-
const fmData = data;
|
|
1137
|
-
|
|
1291
|
+
const { data, content: rawContent } = matter(raw, matterOptions);
|
|
1292
|
+
const fmData = { ...options.config.siteConfig.frontmatter, ...data };
|
|
1293
|
+
const content = stripEncryptedContent(rawContent);
|
|
1294
|
+
const separator = content.indexOf(EXCERPT_SEPARATOR);
|
|
1295
|
+
const excerpt = separator < 0 ? "" : content.slice(0, separator);
|
|
1296
|
+
const relative = relativePagePath(i, options.userRoot);
|
|
1297
|
+
if (relative && isUnpublishedPage(relative, options.config.siteConfig.publishing))
|
|
1298
|
+
continue;
|
|
1299
|
+
if (fmData.draft && !options.config.siteConfig.publishing?.drafts) {
|
|
1138
1300
|
consola.warn(`Ignore draft post: ${colors.dim(i)}`);
|
|
1139
1301
|
continue;
|
|
1140
1302
|
}
|
|
1141
1303
|
if (fmData.hide)
|
|
1142
1304
|
continue;
|
|
1143
|
-
if (fmData.password)
|
|
1305
|
+
if (fmData.password || fmData.encrypt === true)
|
|
1144
1306
|
continue;
|
|
1145
1307
|
const extendKeys = options.config.fuse?.extendKeys || [];
|
|
1146
1308
|
const relativeLink = path.join(options.config.vite?.base || "/", getPagePath(i, options.userRoot) || path.relative(path.resolve(options.userRoot, "pages"), i)).replace(/\\/g, "/");
|
|
@@ -1158,7 +1320,10 @@ async function generateFuseList(options) {
|
|
|
1158
1320
|
fuseListItem.content = content;
|
|
1159
1321
|
}
|
|
1160
1322
|
extendKeys.forEach((key) => {
|
|
1161
|
-
|
|
1323
|
+
if (SENSITIVE_FRONTMATTER_KEYS.has(key) || key === "photos" && "gallery_password" in fmData)
|
|
1324
|
+
return;
|
|
1325
|
+
const value = fmData[key] || "";
|
|
1326
|
+
fuseListItem[key] = typeof value === "string" ? stripEncryptedContent(value) : value;
|
|
1162
1327
|
});
|
|
1163
1328
|
posts.push(fuseListItem);
|
|
1164
1329
|
}
|
|
@@ -1200,7 +1365,7 @@ function registerFuseCommand(cli) {
|
|
|
1200
1365
|
(args) => commonOptions(args).strict().help(),
|
|
1201
1366
|
async ({ root }) => {
|
|
1202
1367
|
setEnvProd();
|
|
1203
|
-
const options = await resolveOptions$
|
|
1368
|
+
const options = await resolveOptions$2({ userRoot: root }, "build");
|
|
1204
1369
|
await execFuse(options);
|
|
1205
1370
|
}
|
|
1206
1371
|
);
|
|
@@ -1219,15 +1384,24 @@ const fuseModule = defineValaxyModule({
|
|
|
1219
1384
|
async function scanPageFiles(userRoot, include) {
|
|
1220
1385
|
return [...(await discoverPageFiles(userRoot, include)).values()];
|
|
1221
1386
|
}
|
|
1222
|
-
async function readPostFiles(files) {
|
|
1387
|
+
async function readPostFiles(files, defaults = {}) {
|
|
1223
1388
|
return Promise.all(files.map(async (filePath) => {
|
|
1224
1389
|
const raw = await readFile(filePath, "utf-8");
|
|
1225
1390
|
const { data, content, excerpt } = matter(raw, matterOptions);
|
|
1226
|
-
return { data, content, excerpt, filePath };
|
|
1391
|
+
return { data: { ...defaults, ...data }, content, excerpt, filePath };
|
|
1227
1392
|
}));
|
|
1228
1393
|
}
|
|
1229
|
-
function filterPublicPosts(posts) {
|
|
1230
|
-
return posts.filter(({ data }) =>
|
|
1394
|
+
function filterPublicPosts(posts, publishing, userRoot) {
|
|
1395
|
+
return posts.filter(({ data, filePath }) => {
|
|
1396
|
+
if (data.password || data.encrypt === true || data.hide)
|
|
1397
|
+
return false;
|
|
1398
|
+
if (data.draft && !publishing?.drafts)
|
|
1399
|
+
return false;
|
|
1400
|
+
const relative = relativePagePath(filePath, userRoot);
|
|
1401
|
+
if (relative && isUnpublishedPage(relative, publishing))
|
|
1402
|
+
return false;
|
|
1403
|
+
return true;
|
|
1404
|
+
});
|
|
1231
1405
|
}
|
|
1232
1406
|
function filePathToUrlPath(filePath, userRoot) {
|
|
1233
1407
|
const relativePath = getPagePath(filePath, userRoot) || path.relative(path.join(userRoot, "pages"), filePath);
|
|
@@ -1260,15 +1434,15 @@ async function loadLlmsPosts(options) {
|
|
|
1260
1434
|
loadLocalesYml(path.resolve(options.userRoot, "locales"));
|
|
1261
1435
|
const include = llmsConfig.include || ["posts/**/*.md"];
|
|
1262
1436
|
const files = await scanPageFiles(options.userRoot, include);
|
|
1263
|
-
const rawPosts = await readPostFiles(files);
|
|
1264
|
-
const publicPosts = filterPublicPosts(rawPosts);
|
|
1437
|
+
const rawPosts = await readPostFiles(files, siteConfig.frontmatter);
|
|
1438
|
+
const publicPosts = filterPublicPosts(rawPosts, siteConfig.publishing, options.userRoot);
|
|
1265
1439
|
const posts = publicPosts.map(({ data, content, filePath }) => ({
|
|
1266
1440
|
title: resolveText(data.title, lang) || path.basename(filePath, ".md"),
|
|
1267
1441
|
description: resolveText(data.description, lang) || "",
|
|
1268
1442
|
date: data.date ? new Date(data.date) : /* @__PURE__ */ new Date(0),
|
|
1269
1443
|
urlPath: filePathToUrlPath(filePath, options.userRoot),
|
|
1270
1444
|
sourcePath: getPagePath(filePath, options.userRoot),
|
|
1271
|
-
content,
|
|
1445
|
+
content: stripEncryptedContent(content),
|
|
1272
1446
|
rawFrontmatter: stripSensitiveFrontmatter(data)
|
|
1273
1447
|
}));
|
|
1274
1448
|
posts.sort((a, b) => +b.date - +a.date);
|
|
@@ -1678,7 +1852,7 @@ const llmsModule = defineValaxyModule({
|
|
|
1678
1852
|
(args) => commonOptions(args).strict().help(),
|
|
1679
1853
|
async ({ root }) => {
|
|
1680
1854
|
setEnvProd();
|
|
1681
|
-
const options = await resolveOptions$
|
|
1855
|
+
const options = await resolveOptions$2({ userRoot: root }, "build");
|
|
1682
1856
|
await build$2(options);
|
|
1683
1857
|
}
|
|
1684
1858
|
);
|
|
@@ -1751,11 +1925,7 @@ async function build$1(options) {
|
|
|
1751
1925
|
return;
|
|
1752
1926
|
}
|
|
1753
1927
|
const siteUrl = siteConfig.url;
|
|
1754
|
-
const author =
|
|
1755
|
-
name: siteConfig.author?.name,
|
|
1756
|
-
email: siteConfig.author?.email,
|
|
1757
|
-
link: siteConfig.author?.link
|
|
1758
|
-
};
|
|
1928
|
+
const author = publicAuthor(siteConfig.author);
|
|
1759
1929
|
const ccVersion = siteConfig.license?.type === "zero" ? "1.0" : "4.0";
|
|
1760
1930
|
const feedNameMap = {
|
|
1761
1931
|
atom: siteConfig.feed?.name ? `${siteConfig.feed?.name}.atom` : "atom.xml",
|
|
@@ -1800,15 +1970,19 @@ async function getPosts(params, options) {
|
|
|
1800
1970
|
const readFilePromises = files.map(async (i) => {
|
|
1801
1971
|
const raw = await readFile(i, "utf-8");
|
|
1802
1972
|
const { data, content, excerpt } = matter(raw, matterOptions);
|
|
1803
|
-
|
|
1973
|
+
const frontmatter = { ...siteConfig.frontmatter, ...data };
|
|
1974
|
+
return { data: frontmatter, content, excerpt, path: i };
|
|
1804
1975
|
});
|
|
1805
1976
|
const rawPosts = await Promise.all(readFilePromises);
|
|
1806
1977
|
const draftPosts = [];
|
|
1807
1978
|
const filteredPosts = rawPosts.filter((p) => {
|
|
1808
1979
|
const { data } = p;
|
|
1809
|
-
if (data.password)
|
|
1980
|
+
if (data.password || data.encrypt === true)
|
|
1981
|
+
return false;
|
|
1982
|
+
const relative2 = relativePagePath(p.path, options.userRoot);
|
|
1983
|
+
if (relative2 && isUnpublishedPage(relative2, siteConfig.publishing))
|
|
1810
1984
|
return false;
|
|
1811
|
-
if (data.draft) {
|
|
1985
|
+
if (data.draft && !siteConfig.publishing?.drafts) {
|
|
1812
1986
|
draftPosts.push(p.path);
|
|
1813
1987
|
return false;
|
|
1814
1988
|
}
|
|
@@ -1822,7 +1996,12 @@ ${draftPosts.map((p) => ` ${colors.dim("-")} ${colors.dim(p)}`).join("\n")}`);
|
|
|
1822
1996
|
}
|
|
1823
1997
|
const posts = [];
|
|
1824
1998
|
for (const rawPost of filteredPosts) {
|
|
1825
|
-
const { data, path
|
|
1999
|
+
const { data, path } = rawPost;
|
|
2000
|
+
const content = stripEncryptedContent(rawPost.content);
|
|
2001
|
+
const excerpt = content.includes(EXCERPT_SEPARATOR) ? content.split(EXCERPT_SEPARATOR)[0] : "";
|
|
2002
|
+
const description = tObject(data.description, lang);
|
|
2003
|
+
const manualExcerpt = tObject(data.excerpt, lang);
|
|
2004
|
+
const summaryLength = siteConfig.excerpt?.length || 200;
|
|
1826
2005
|
if (!data.date)
|
|
1827
2006
|
data.date = await getCreatedTime(path);
|
|
1828
2007
|
if (siteConfig.lastUpdated) {
|
|
@@ -1868,7 +2047,7 @@ ${draftPosts.map((p) => ` ${colors.dim("-")} ${colors.dim(p)}`).join("\n")}`);
|
|
|
1868
2047
|
const item = {
|
|
1869
2048
|
...data,
|
|
1870
2049
|
title: tObject(data.title, lang),
|
|
1871
|
-
description:
|
|
2050
|
+
description: typeof description === "string" && description.trim() ? description : plainSeoDescription(typeof manualExcerpt === "string" ? manualExcerpt : "", summaryLength) || plainSeoDescription(excerpt || content, summaryLength),
|
|
1872
2051
|
date: new Date(data.date),
|
|
1873
2052
|
// RSS pubDate / JSON date_published
|
|
1874
2053
|
published: new Date(data.date),
|
|
@@ -1968,7 +2147,7 @@ const rssModule = defineValaxyModule({
|
|
|
1968
2147
|
(args) => commonOptions(args).strict().help(),
|
|
1969
2148
|
async ({ root }) => {
|
|
1970
2149
|
setEnvProd();
|
|
1971
|
-
const options = await resolveOptions$
|
|
2150
|
+
const options = await resolveOptions$2({ userRoot: root }, "build");
|
|
1972
2151
|
await build$1(options);
|
|
1973
2152
|
}
|
|
1974
2153
|
);
|
|
@@ -2266,7 +2445,7 @@ function createValaxyNode(options) {
|
|
|
2266
2445
|
return valaxyNode;
|
|
2267
2446
|
}
|
|
2268
2447
|
|
|
2269
|
-
function toArray(array) {
|
|
2448
|
+
function toArray$1(array) {
|
|
2270
2449
|
array = array ?? [];
|
|
2271
2450
|
return Array.isArray(array) ? array : [array];
|
|
2272
2451
|
}
|
|
@@ -2380,7 +2559,7 @@ function stringifyComponentImport({ as: name, from: path, name: importName, side
|
|
|
2380
2559
|
from: path,
|
|
2381
2560
|
name: importName
|
|
2382
2561
|
})];
|
|
2383
|
-
if (sideEffects) toArray(sideEffects).forEach((i) => imports.push(stringifyImport(i)));
|
|
2562
|
+
if (sideEffects) toArray$1(sideEffects).forEach((i) => imports.push(stringifyImport(i)));
|
|
2384
2563
|
return imports.join(";");
|
|
2385
2564
|
}
|
|
2386
2565
|
function getNameFromFilePath(filePath, options) {
|
|
@@ -2613,7 +2792,7 @@ const defaultOptions = {
|
|
|
2613
2792
|
prefix: ""
|
|
2614
2793
|
};
|
|
2615
2794
|
function normalizeResolvers(resolvers) {
|
|
2616
|
-
return toArray(resolvers).flat().map((r) => typeof r === "function" ? {
|
|
2795
|
+
return toArray$1(resolvers).flat().map((r) => typeof r === "function" ? {
|
|
2617
2796
|
resolve: r,
|
|
2618
2797
|
type: "component"
|
|
2619
2798
|
} : r);
|
|
@@ -2622,16 +2801,16 @@ function resolveGlobsExclude(root, glob2) {
|
|
|
2622
2801
|
const excludeReg = /^!/;
|
|
2623
2802
|
return slash(`${excludeReg.test(glob2) ? "!" : ""}${resolve(root, glob2.replace(excludeReg, ""))}`);
|
|
2624
2803
|
}
|
|
2625
|
-
function resolveOptions(options, root) {
|
|
2804
|
+
function resolveOptions$1(options, root) {
|
|
2626
2805
|
const resolved = Object.assign({}, defaultOptions, options);
|
|
2627
2806
|
resolved.resolvers = normalizeResolvers(resolved.resolvers);
|
|
2628
|
-
resolved.extensions = toArray(resolved.extensions);
|
|
2807
|
+
resolved.extensions = toArray$1(resolved.extensions);
|
|
2629
2808
|
if (resolved.globs) {
|
|
2630
|
-
resolved.globs = toArray(resolved.globs).map((glob2) => resolveGlobsExclude(root, glob2));
|
|
2809
|
+
resolved.globs = toArray$1(resolved.globs).map((glob2) => resolveGlobsExclude(root, glob2));
|
|
2631
2810
|
resolved.resolvedDirs = [];
|
|
2632
2811
|
} else {
|
|
2633
2812
|
const extsGlob = resolved.extensions.length === 1 ? resolved.extensions : `{${resolved.extensions.join(",")}}`;
|
|
2634
|
-
resolved.dirs = toArray(resolved.dirs);
|
|
2813
|
+
resolved.dirs = toArray$1(resolved.dirs);
|
|
2635
2814
|
const globs = resolved.dirs.map((i) => resolveGlobsExclude(root, i));
|
|
2636
2815
|
resolved.resolvedDirs = globs.filter((i) => !i.startsWith("!"));
|
|
2637
2816
|
resolved.globs = globs.map((i) => {
|
|
@@ -2644,7 +2823,7 @@ function resolveOptions(options, root) {
|
|
|
2644
2823
|
});
|
|
2645
2824
|
if (!resolved.extensions.length) throw new Error("[unplugin-vue-components] `extensions` option is required to search for components");
|
|
2646
2825
|
}
|
|
2647
|
-
resolved.globsExclude = toArray(resolved.globsExclude || []).map((i) => resolveGlobsExclude(root, i));
|
|
2826
|
+
resolved.globsExclude = toArray$1(resolved.globsExclude || []).map((i) => resolveGlobsExclude(root, i));
|
|
2648
2827
|
resolved.globs = resolved.globs.filter((i) => {
|
|
2649
2828
|
if (!i.startsWith("!")) return true;
|
|
2650
2829
|
resolved.globsExclude.push(i.slice(1));
|
|
@@ -2775,7 +2954,7 @@ var Context = class {
|
|
|
2775
2954
|
dumpComponentsInfoPath;
|
|
2776
2955
|
constructor(rawOptions) {
|
|
2777
2956
|
this.rawOptions = rawOptions;
|
|
2778
|
-
this.options = resolveOptions(rawOptions, this.root);
|
|
2957
|
+
this.options = resolveOptions$1(rawOptions, this.root);
|
|
2779
2958
|
this.sourcemap = rawOptions.sourcemap ?? true;
|
|
2780
2959
|
this.generateDeclaration = throttle(500, this._generateDeclaration.bind(this), { noLeading: false });
|
|
2781
2960
|
this._removeUnused = this.options.syncMode !== "append";
|
|
@@ -2790,7 +2969,7 @@ var Context = class {
|
|
|
2790
2969
|
if (this.root === root) return;
|
|
2791
2970
|
debug$5.env("root", root);
|
|
2792
2971
|
this.root = root;
|
|
2793
|
-
this.options = resolveOptions(this.rawOptions, this.root);
|
|
2972
|
+
this.options = resolveOptions$1(this.rawOptions, this.root);
|
|
2794
2973
|
}
|
|
2795
2974
|
transform(code, id) {
|
|
2796
2975
|
const { path, query } = parseId(id);
|
|
@@ -2851,7 +3030,7 @@ var Context = class {
|
|
|
2851
3030
|
addComponents(paths) {
|
|
2852
3031
|
debug$5.components("add", paths);
|
|
2853
3032
|
const size = this._componentPaths.size;
|
|
2854
|
-
toArray(paths).forEach((p) => this._componentPaths.add(p));
|
|
3033
|
+
toArray$1(paths).forEach((p) => this._componentPaths.add(p));
|
|
2855
3034
|
if (this._componentPaths.size !== size) {
|
|
2856
3035
|
this.updateComponentNameMap();
|
|
2857
3036
|
return true;
|
|
@@ -2867,7 +3046,7 @@ var Context = class {
|
|
|
2867
3046
|
removeComponents(paths) {
|
|
2868
3047
|
debug$5.components("remove", paths);
|
|
2869
3048
|
const size = this._componentPaths.size;
|
|
2870
|
-
toArray(paths).forEach((p) => this._componentPaths.delete(p));
|
|
3049
|
+
toArray$1(paths).forEach((p) => this._componentPaths.delete(p));
|
|
2871
3050
|
if (this._componentPaths.size !== size) {
|
|
2872
3051
|
this.updateComponentNameMap();
|
|
2873
3052
|
return true;
|
|
@@ -3492,7 +3671,7 @@ async function mergeViteConfigs({ userRoot, themeRoot }, command) {
|
|
|
3492
3671
|
command
|
|
3493
3672
|
};
|
|
3494
3673
|
let resolvedConfig = {};
|
|
3495
|
-
const files = uniq([themeRoot, userRoot]).map((i) => join(i, "vite.config.ts"));
|
|
3674
|
+
const files = uniq$1([themeRoot, userRoot]).map((i) => join(i, "vite.config.ts"));
|
|
3496
3675
|
const loadViteConfigPromiseArr = files.map(async (file) => {
|
|
3497
3676
|
if (!await fs.exists(file))
|
|
3498
3677
|
return;
|
|
@@ -3619,13 +3798,16 @@ function createConfigPlugin(options) {
|
|
|
3619
3798
|
const addonDeps = options.addons.map((i) => Object.keys(i.pkg.dependencies || {})).flat();
|
|
3620
3799
|
const cdnModuleNames = options.mode === "build" ? (options.config.cdn?.modules || []).map((m) => m.name) : [];
|
|
3621
3800
|
const katexEnabled = isKatexPluginNeeded(options.config);
|
|
3801
|
+
const searchRoot = normalizePath(resolve(options.clientRoot, "composables/search"));
|
|
3622
3802
|
const depsToInclude = [...clientDeps];
|
|
3803
|
+
if (options.config.vue?.browserTemplateCompilation !== false)
|
|
3804
|
+
depsToInclude.push("vue/dist/vue.esm-bundler.js");
|
|
3623
3805
|
if (!katexEnabled) {
|
|
3624
3806
|
const katexIdx = depsToInclude.indexOf("katex");
|
|
3625
3807
|
if (katexIdx !== -1)
|
|
3626
3808
|
depsToInclude.splice(katexIdx, 1);
|
|
3627
3809
|
}
|
|
3628
|
-
const includedDeps = uniq([
|
|
3810
|
+
const includedDeps = uniq$1([
|
|
3629
3811
|
...depsToInclude,
|
|
3630
3812
|
// remove theme deps, for primevue parse entry
|
|
3631
3813
|
// ...themeDeps,
|
|
@@ -3671,11 +3853,11 @@ function createConfigPlugin(options) {
|
|
|
3671
3853
|
entries: [resolve(options.clientRoot, "main.ts")],
|
|
3672
3854
|
// must need it
|
|
3673
3855
|
include: includedDeps,
|
|
3674
|
-
exclude: uniq([...EXCLUDE, ...addonNames])
|
|
3856
|
+
exclude: uniq$1([...EXCLUDE, ...addonNames])
|
|
3675
3857
|
},
|
|
3676
3858
|
server: {
|
|
3677
3859
|
fs: {
|
|
3678
|
-
allow: uniq(fsAllow)
|
|
3860
|
+
allow: uniq$1(fsAllow)
|
|
3679
3861
|
}
|
|
3680
3862
|
}
|
|
3681
3863
|
};
|
|
@@ -3684,6 +3866,13 @@ function createConfigPlugin(options) {
|
|
|
3684
3866
|
}
|
|
3685
3867
|
return injection;
|
|
3686
3868
|
},
|
|
3869
|
+
transform: {
|
|
3870
|
+
filter: { id: new RegExp(`^${escapeRegExp(searchRoot)}/[^/]+\\.ts$`) },
|
|
3871
|
+
handler() {
|
|
3872
|
+
if (options.mode === "build")
|
|
3873
|
+
return { moduleSideEffects: false };
|
|
3874
|
+
}
|
|
3875
|
+
},
|
|
3687
3876
|
async transformIndexHtml(html, ctx) {
|
|
3688
3877
|
html = await getIndexHtml(options, html);
|
|
3689
3878
|
return {
|
|
@@ -3719,10 +3908,14 @@ async function getAlias(options) {
|
|
|
3719
3908
|
{ find: `valaxy-theme-${options.theme}/`, replacement: `${toAtFS(resolve(options.themeRoot))}/` },
|
|
3720
3909
|
{ find: `valaxy-theme-${options.theme}`, replacement: `${toAtFS(resolve(options.themeRoot))}/client/index.ts` }
|
|
3721
3910
|
];
|
|
3722
|
-
if (options.config.vue?.browserTemplateCompilation) {
|
|
3911
|
+
if (options.config.vue?.browserTemplateCompilation === true) {
|
|
3723
3912
|
alias.push(
|
|
3724
3913
|
{ find: /^vue$/, replacement: await resolveImportPath("vue/dist/vue.esm-bundler.js", true) }
|
|
3725
3914
|
);
|
|
3915
|
+
} else if (options.config.vue?.browserTemplateCompilation === false) {
|
|
3916
|
+
alias.push(
|
|
3917
|
+
{ find: "vue/dist/vue.esm-bundler.js", replacement: await resolveImportPath("vue/dist/vue.runtime.esm-bundler.js", true) }
|
|
3918
|
+
);
|
|
3726
3919
|
}
|
|
3727
3920
|
const vueRouterPkg = await resolveImportPath("vue-router/package.json");
|
|
3728
3921
|
if (vueRouterPkg)
|
|
@@ -3755,8 +3948,6 @@ async function getAlias(options) {
|
|
|
3755
3948
|
const LAYOUTS_MODULE_ID = "virtual:generated-layouts";
|
|
3756
3949
|
const RESOLVED_LAYOUTS_MODULE_ID = `\0${LAYOUTS_MODULE_ID}`;
|
|
3757
3950
|
function defaultImportMode(name) {
|
|
3758
|
-
if (process.env.VITE_SSG)
|
|
3759
|
-
return "sync";
|
|
3760
3951
|
return name === "default" ? "sync" : "async";
|
|
3761
3952
|
}
|
|
3762
3953
|
const REGEX_BACKSLASH = /\\/g;
|
|
@@ -3860,11 +4051,9 @@ function resolveLayoutsOptions(options, userOptions = {}) {
|
|
|
3860
4051
|
extensions: ["vue"],
|
|
3861
4052
|
exclude: [],
|
|
3862
4053
|
defaultLayout: "default",
|
|
3863
|
-
//
|
|
3864
|
-
//
|
|
3865
|
-
|
|
3866
|
-
// hydration starts, causing a mismatch.
|
|
3867
|
-
importMode: options.mode === "build" ? () => "sync" : defaultImportMode,
|
|
4054
|
+
// LayoutWrapper waits for the active layout in its navigation guards,
|
|
4055
|
+
// before router.isReady() allows SSR or client hydration to begin.
|
|
4056
|
+
importMode: defaultImportMode,
|
|
3868
4057
|
inheritDefaultLayout: true
|
|
3869
4058
|
};
|
|
3870
4059
|
for (const [key, value] of Object.entries(userOptions)) {
|
|
@@ -4028,16 +4217,21 @@ async function resolveRawMd(url, options) {
|
|
|
4028
4217
|
if (!filePath)
|
|
4029
4218
|
return null;
|
|
4030
4219
|
const raw = await fs.readFile(filePath, "utf-8");
|
|
4031
|
-
const
|
|
4032
|
-
|
|
4220
|
+
const parsed = matter(raw, matterOptions);
|
|
4221
|
+
const data = { ...options.config.siteConfig.frontmatter, ...parsed.data };
|
|
4222
|
+
const content = stripEncryptedContent(parsed.content);
|
|
4223
|
+
const publishing = options.config.siteConfig.publishing;
|
|
4224
|
+
const relative = relativePagePath(filePath, options.userRoot);
|
|
4225
|
+
if (data.password || data.encrypt === true || data.hide || data.draft && !publishing?.drafts)
|
|
4226
|
+
return null;
|
|
4227
|
+
if (relative && isUnpublishedPage(relative, publishing))
|
|
4033
4228
|
return null;
|
|
4034
4229
|
const lang = options.config.siteConfig.lang || "en";
|
|
4035
4230
|
url.replace(/\.md$/, "");
|
|
4036
4231
|
const cleanedFrontmatter = stripSensitiveFrontmatter(data);
|
|
4037
4232
|
const post = {
|
|
4038
|
-
title: resolveText(data.title, lang) || path.basename(filePath, ".md"),
|
|
4039
|
-
description: resolveText(data.description, lang) || "",
|
|
4040
|
-
date: data.date ? new Date(data.date) : /* @__PURE__ */ new Date(0),
|
|
4233
|
+
title: resolveText(data.title || "", lang) || path.basename(filePath, ".md"),
|
|
4234
|
+
description: resolveText(data.description || "", lang) || "",
|
|
4041
4235
|
sourcePath: getPagePath(filePath, options.userRoot),
|
|
4042
4236
|
rawFrontmatter: cleanedFrontmatter
|
|
4043
4237
|
};
|
|
@@ -5473,6 +5667,664 @@ async function setupMarkdownPlugins(md, options, base = options?.config.vite?.ba
|
|
|
5473
5667
|
return md;
|
|
5474
5668
|
}
|
|
5475
5669
|
|
|
5670
|
+
//#region src/html-re.ts
|
|
5671
|
+
const attr_name = "[a-zA-Z_:@][a-zA-Z0-9:._-]*";
|
|
5672
|
+
const attribute = "(?:\\s+" + attr_name + "(?:\\s*=\\s*(?:[^\"'=<>`\\x00-\\x20]+|'[^']*'|\"[^\"]*\"))?)";
|
|
5673
|
+
const open_tag = "<[A-Za-z][A-Za-z0-9\\-]*" + attribute + "*\\s*\\/?>";
|
|
5674
|
+
const HTML_TAG_RE = /* @__PURE__ */ new RegExp("^(?:" + open_tag + "|<\\/[A-Za-z][A-Za-z0-9\\-]*\\s*>|<!---->|<!--(?:-?[^>-])(?:-?[^-])*-->|<[?][\\s\\S]*?[?]>|<![A-Z]+\\s+[^>]*>|<!\\[CDATA\\[[\\s\\S]*?\\]\\]>)");
|
|
5675
|
+
const HTML_OPEN_CLOSE_TAG_RE = /* @__PURE__ */ new RegExp("^(?:" + open_tag + "|<\\/[A-Za-z][A-Za-z0-9\\-]*\\s*>)");
|
|
5676
|
+
const HTML_SELF_CLOSING_TAG_RE = /* @__PURE__ */ new RegExp("^<[A-Za-z][A-Za-z0-9\\-]*" + attribute + "*\\s*\\/>");
|
|
5677
|
+
const HTML_OPEN_AND_CLOSE_TAG_IN_THE_SAME_LINE_RE = /* @__PURE__ */ new RegExp("^<([A-Za-z][A-Za-z0-9\\-]*)" + attribute + "*\\s*>.*<\\/\\1\\s*>");
|
|
5678
|
+
|
|
5679
|
+
//#endregion
|
|
5680
|
+
//#region src/tags.ts
|
|
5681
|
+
/**
|
|
5682
|
+
* List of block tags
|
|
5683
|
+
*
|
|
5684
|
+
* @see https://spec.commonmark.org/0.30/#html-blocks
|
|
5685
|
+
* @see https://github.com/markdown-it/markdown-it/blob/master/lib/common/html_blocks.mjs
|
|
5686
|
+
*/
|
|
5687
|
+
const TAGS_BLOCK = [
|
|
5688
|
+
"address",
|
|
5689
|
+
"article",
|
|
5690
|
+
"aside",
|
|
5691
|
+
"base",
|
|
5692
|
+
"basefont",
|
|
5693
|
+
"blockquote",
|
|
5694
|
+
"body",
|
|
5695
|
+
"caption",
|
|
5696
|
+
"center",
|
|
5697
|
+
"col",
|
|
5698
|
+
"colgroup",
|
|
5699
|
+
"dd",
|
|
5700
|
+
"details",
|
|
5701
|
+
"dialog",
|
|
5702
|
+
"dir",
|
|
5703
|
+
"div",
|
|
5704
|
+
"dl",
|
|
5705
|
+
"dt",
|
|
5706
|
+
"fieldset",
|
|
5707
|
+
"figcaption",
|
|
5708
|
+
"figure",
|
|
5709
|
+
"footer",
|
|
5710
|
+
"form",
|
|
5711
|
+
"frame",
|
|
5712
|
+
"frameset",
|
|
5713
|
+
"h1",
|
|
5714
|
+
"h2",
|
|
5715
|
+
"h3",
|
|
5716
|
+
"h4",
|
|
5717
|
+
"h5",
|
|
5718
|
+
"h6",
|
|
5719
|
+
"head",
|
|
5720
|
+
"header",
|
|
5721
|
+
"hr",
|
|
5722
|
+
"html",
|
|
5723
|
+
"iframe",
|
|
5724
|
+
"legend",
|
|
5725
|
+
"li",
|
|
5726
|
+
"link",
|
|
5727
|
+
"main",
|
|
5728
|
+
"menu",
|
|
5729
|
+
"menuitem",
|
|
5730
|
+
"nav",
|
|
5731
|
+
"noframes",
|
|
5732
|
+
"ol",
|
|
5733
|
+
"optgroup",
|
|
5734
|
+
"option",
|
|
5735
|
+
"p",
|
|
5736
|
+
"param",
|
|
5737
|
+
"search",
|
|
5738
|
+
"section",
|
|
5739
|
+
"summary",
|
|
5740
|
+
"table",
|
|
5741
|
+
"tbody",
|
|
5742
|
+
"td",
|
|
5743
|
+
"tfoot",
|
|
5744
|
+
"th",
|
|
5745
|
+
"thead",
|
|
5746
|
+
"title",
|
|
5747
|
+
"tr",
|
|
5748
|
+
"track",
|
|
5749
|
+
"ul"
|
|
5750
|
+
];
|
|
5751
|
+
/**
|
|
5752
|
+
* According to markdown spec, all non-block html tags are treated as "inline"
|
|
5753
|
+
* tags (wrapped with <p></p>), including those "unknown" tags
|
|
5754
|
+
*
|
|
5755
|
+
* Therefore, markdown-it processes "inline" tags and "unknown" tags in the same
|
|
5756
|
+
* way, and does not care if a tag is "inline" or "unknown"
|
|
5757
|
+
*
|
|
5758
|
+
* As we want to take those "unknown" tags as custom components, we should
|
|
5759
|
+
* treat them as "block" tags
|
|
5760
|
+
*
|
|
5761
|
+
* So we have to distinguish between "inline" and "unknown" tags ourselves
|
|
5762
|
+
*
|
|
5763
|
+
* The inline tags list comes from MDN
|
|
5764
|
+
*
|
|
5765
|
+
* @see https://spec.commonmark.org/0.30/#raw-html
|
|
5766
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements
|
|
5767
|
+
*/
|
|
5768
|
+
const TAGS_INLINE = [
|
|
5769
|
+
"a",
|
|
5770
|
+
"abbr",
|
|
5771
|
+
"acronym",
|
|
5772
|
+
"audio",
|
|
5773
|
+
"b",
|
|
5774
|
+
"bdi",
|
|
5775
|
+
"bdo",
|
|
5776
|
+
"big",
|
|
5777
|
+
"br",
|
|
5778
|
+
"button",
|
|
5779
|
+
"canvas",
|
|
5780
|
+
"cite",
|
|
5781
|
+
"code",
|
|
5782
|
+
"data",
|
|
5783
|
+
"datalist",
|
|
5784
|
+
"del",
|
|
5785
|
+
"dfn",
|
|
5786
|
+
"em",
|
|
5787
|
+
"embed",
|
|
5788
|
+
"i",
|
|
5789
|
+
"iframe",
|
|
5790
|
+
"img",
|
|
5791
|
+
"input",
|
|
5792
|
+
"ins",
|
|
5793
|
+
"kbd",
|
|
5794
|
+
"label",
|
|
5795
|
+
"map",
|
|
5796
|
+
"mark",
|
|
5797
|
+
"meter",
|
|
5798
|
+
"noscript",
|
|
5799
|
+
"object",
|
|
5800
|
+
"output",
|
|
5801
|
+
"picture",
|
|
5802
|
+
"progress",
|
|
5803
|
+
"q",
|
|
5804
|
+
"ruby",
|
|
5805
|
+
"s",
|
|
5806
|
+
"samp",
|
|
5807
|
+
"script",
|
|
5808
|
+
"select",
|
|
5809
|
+
"slot",
|
|
5810
|
+
"small",
|
|
5811
|
+
"span",
|
|
5812
|
+
"strong",
|
|
5813
|
+
"sub",
|
|
5814
|
+
"sup",
|
|
5815
|
+
"svg",
|
|
5816
|
+
"template",
|
|
5817
|
+
"textarea",
|
|
5818
|
+
"time",
|
|
5819
|
+
"u",
|
|
5820
|
+
"tt",
|
|
5821
|
+
"var",
|
|
5822
|
+
"video",
|
|
5823
|
+
"wbr"
|
|
5824
|
+
];
|
|
5825
|
+
/**
|
|
5826
|
+
* Tags of Vue built-in components
|
|
5827
|
+
*
|
|
5828
|
+
* @see https://vuejs.org/api/built-in-components.html
|
|
5829
|
+
* @see https://vuejs.org/api/built-in-special-elements.html
|
|
5830
|
+
*/
|
|
5831
|
+
const TAGS_VUE_RESERVED = [
|
|
5832
|
+
"template",
|
|
5833
|
+
"component",
|
|
5834
|
+
"transition",
|
|
5835
|
+
"transition-group",
|
|
5836
|
+
"keep-alive",
|
|
5837
|
+
"slot",
|
|
5838
|
+
"teleport"
|
|
5839
|
+
];
|
|
5840
|
+
|
|
5841
|
+
//#endregion
|
|
5842
|
+
//#region src/html-block-rule.ts
|
|
5843
|
+
/**
|
|
5844
|
+
* ADDED: wrap the `HTML_SEQUENCES` with a function, because we allow user options
|
|
5845
|
+
* to customize the block tags and inline tags
|
|
5846
|
+
*/
|
|
5847
|
+
const createHtmlSequences = ({ blockTags, inlineTags }) => {
|
|
5848
|
+
const forceBlockTags = [...blockTags, ...TAGS_BLOCK];
|
|
5849
|
+
const forceInlineTags = [...inlineTags, ...TAGS_INLINE.filter((item) => !TAGS_VUE_RESERVED.includes(item))];
|
|
5850
|
+
const HTML_SEQUENCES = [
|
|
5851
|
+
[
|
|
5852
|
+
/^<(script|pre|style)(?=(\s|>|$))/i,
|
|
5853
|
+
/<\/(script|pre|style)>/i,
|
|
5854
|
+
true
|
|
5855
|
+
],
|
|
5856
|
+
[
|
|
5857
|
+
/^<!--/,
|
|
5858
|
+
/-->/,
|
|
5859
|
+
true
|
|
5860
|
+
],
|
|
5861
|
+
[
|
|
5862
|
+
/^<\?/,
|
|
5863
|
+
/\?>/,
|
|
5864
|
+
true
|
|
5865
|
+
],
|
|
5866
|
+
[
|
|
5867
|
+
/^<![A-Z]/,
|
|
5868
|
+
/>/,
|
|
5869
|
+
true
|
|
5870
|
+
],
|
|
5871
|
+
[
|
|
5872
|
+
/^<!\[CDATA\[/,
|
|
5873
|
+
/\]\]>/,
|
|
5874
|
+
true
|
|
5875
|
+
],
|
|
5876
|
+
[
|
|
5877
|
+
new RegExp("^</?(" + forceBlockTags.join("|") + ")(?=(\\s|/?>|$))", "i"),
|
|
5878
|
+
/^$/,
|
|
5879
|
+
true
|
|
5880
|
+
],
|
|
5881
|
+
[
|
|
5882
|
+
/* @__PURE__ */ new RegExp("^</?(?!(" + forceInlineTags.join("|") + ")(?![\\w-]))[A-Za-z][A-Za-z0-9\\-]*(?=(\\s|/?>|$))"),
|
|
5883
|
+
/^$/,
|
|
5884
|
+
true
|
|
5885
|
+
],
|
|
5886
|
+
[
|
|
5887
|
+
/* @__PURE__ */ new RegExp(HTML_OPEN_CLOSE_TAG_RE.source + "\\s*$"),
|
|
5888
|
+
/^$/,
|
|
5889
|
+
false
|
|
5890
|
+
]
|
|
5891
|
+
];
|
|
5892
|
+
return HTML_SEQUENCES;
|
|
5893
|
+
};
|
|
5894
|
+
const createHtmlBlockRule = (options) => {
|
|
5895
|
+
const HTML_SEQUENCES = createHtmlSequences(options);
|
|
5896
|
+
return (state, startLine, endLine, silent) => {
|
|
5897
|
+
let i;
|
|
5898
|
+
let nextLine;
|
|
5899
|
+
let lineText;
|
|
5900
|
+
let pos = state.bMarks[startLine] + state.tShift[startLine];
|
|
5901
|
+
let max = state.eMarks[startLine];
|
|
5902
|
+
if (state.sCount[startLine] - state.blkIndent >= 4) return false;
|
|
5903
|
+
if (!state.md.options.html) return false;
|
|
5904
|
+
if (state.src.charCodeAt(pos) !== 60) return false;
|
|
5905
|
+
lineText = state.src.slice(pos, max);
|
|
5906
|
+
for (i = 0; i < HTML_SEQUENCES.length; i++) if (HTML_SEQUENCES[i][0].test(lineText)) break;
|
|
5907
|
+
if (i === HTML_SEQUENCES.length) return false;
|
|
5908
|
+
if (silent) return HTML_SEQUENCES[i][2];
|
|
5909
|
+
if (i === 6) {
|
|
5910
|
+
const match = lineText.match(HTML_SELF_CLOSING_TAG_RE) ?? lineText.match(HTML_OPEN_AND_CLOSE_TAG_IN_THE_SAME_LINE_RE);
|
|
5911
|
+
if (match) {
|
|
5912
|
+
state.line = startLine + 1;
|
|
5913
|
+
let token$1 = state.push("html_inline", "", 0);
|
|
5914
|
+
token$1.content = match[0];
|
|
5915
|
+
token$1.map = [startLine, state.line];
|
|
5916
|
+
token$1 = state.push("inline", "", 0);
|
|
5917
|
+
token$1.content = lineText.slice(match[0].length);
|
|
5918
|
+
token$1.map = [startLine, state.line];
|
|
5919
|
+
token$1.children = [];
|
|
5920
|
+
return true;
|
|
5921
|
+
}
|
|
5922
|
+
}
|
|
5923
|
+
nextLine = startLine + 1;
|
|
5924
|
+
if (!HTML_SEQUENCES[i][1].test(lineText)) for (; nextLine < endLine; nextLine++) {
|
|
5925
|
+
if (state.sCount[nextLine] < state.blkIndent) break;
|
|
5926
|
+
pos = state.bMarks[nextLine] + state.tShift[nextLine];
|
|
5927
|
+
max = state.eMarks[nextLine];
|
|
5928
|
+
lineText = state.src.slice(pos, max);
|
|
5929
|
+
if (HTML_SEQUENCES[i][1].test(lineText)) {
|
|
5930
|
+
if (lineText.length !== 0) nextLine++;
|
|
5931
|
+
break;
|
|
5932
|
+
}
|
|
5933
|
+
}
|
|
5934
|
+
state.line = nextLine;
|
|
5935
|
+
const token = state.push("html_block", "", 0);
|
|
5936
|
+
token.map = [startLine, nextLine];
|
|
5937
|
+
token.content = state.getLines(startLine, nextLine, state.blkIndent, true);
|
|
5938
|
+
return true;
|
|
5939
|
+
};
|
|
5940
|
+
};
|
|
5941
|
+
|
|
5942
|
+
//#endregion
|
|
5943
|
+
//#region src/html-inline-rule.ts
|
|
5944
|
+
const isLetter = (ch) => {
|
|
5945
|
+
const lc = ch | 32;
|
|
5946
|
+
return lc >= 97 && lc <= 122;
|
|
5947
|
+
};
|
|
5948
|
+
const htmlInlineRule = (state, silent) => {
|
|
5949
|
+
const { pos } = state;
|
|
5950
|
+
if (!state.md.options.html) return false;
|
|
5951
|
+
const max = state.posMax;
|
|
5952
|
+
if (state.src.charCodeAt(pos) !== 60 || pos + 2 >= max) return false;
|
|
5953
|
+
const ch = state.src.charCodeAt(pos + 1);
|
|
5954
|
+
if (ch !== 33 && ch !== 63 && ch !== 47 && !isLetter(ch)) return false;
|
|
5955
|
+
const match = state.src.slice(pos).match(HTML_TAG_RE);
|
|
5956
|
+
if (!match) return false;
|
|
5957
|
+
if (!silent) {
|
|
5958
|
+
const token = state.push("html_inline", "", 0);
|
|
5959
|
+
token.content = state.src.slice(pos, pos + match[0].length);
|
|
5960
|
+
}
|
|
5961
|
+
state.pos += match[0].length;
|
|
5962
|
+
return true;
|
|
5963
|
+
};
|
|
5964
|
+
|
|
5965
|
+
//#endregion
|
|
5966
|
+
//#region src/component-plugin.ts
|
|
5967
|
+
/**
|
|
5968
|
+
* Allows better use of Vue components in Markdown
|
|
5969
|
+
*/
|
|
5970
|
+
const componentPlugin = (md, { blockTags = [], inlineTags = [] } = {}) => {
|
|
5971
|
+
const htmlBlockRule = createHtmlBlockRule({
|
|
5972
|
+
blockTags,
|
|
5973
|
+
inlineTags
|
|
5974
|
+
});
|
|
5975
|
+
md.block.ruler.at("html_block", htmlBlockRule, { alt: [
|
|
5976
|
+
"paragraph",
|
|
5977
|
+
"reference",
|
|
5978
|
+
"blockquote"
|
|
5979
|
+
] });
|
|
5980
|
+
md.inline.ruler.at("html_inline", htmlInlineRule);
|
|
5981
|
+
};
|
|
5982
|
+
|
|
5983
|
+
//#region src/frontmatter-plugin.ts
|
|
5984
|
+
/**
|
|
5985
|
+
* Get markdown frontmatter and excerpt
|
|
5986
|
+
*
|
|
5987
|
+
* Extract them into env
|
|
5988
|
+
*/
|
|
5989
|
+
const frontmatterPlugin = (md, { grayMatterOptions, renderExcerpt = true } = {}) => {
|
|
5990
|
+
const parse = md.parse.bind(md);
|
|
5991
|
+
md.parse = (src, env = {}) => {
|
|
5992
|
+
const { data, content, excerpt = "" } = matter(src, grayMatterOptions);
|
|
5993
|
+
env.content = content;
|
|
5994
|
+
env.frontmatter = {
|
|
5995
|
+
...env.frontmatter,
|
|
5996
|
+
...data
|
|
5997
|
+
};
|
|
5998
|
+
env.excerpt = renderExcerpt && excerpt ? md.render(excerpt, { ...env }) : excerpt;
|
|
5999
|
+
return parse(content, env);
|
|
6000
|
+
};
|
|
6001
|
+
};
|
|
6002
|
+
|
|
6003
|
+
//#region \0rolldown/runtime.js
|
|
6004
|
+
var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
|
|
6005
|
+
//#endregion
|
|
6006
|
+
//#region node_modules/.pnpm/@antfu+utils@9.3.0/node_modules/@antfu/utils/dist/index.mjs
|
|
6007
|
+
function toArray(array) {
|
|
6008
|
+
array = array ?? [];
|
|
6009
|
+
return Array.isArray(array) ? array : [array];
|
|
6010
|
+
}
|
|
6011
|
+
function uniq(array) {
|
|
6012
|
+
return Array.from(new Set(array));
|
|
6013
|
+
}
|
|
6014
|
+
//#endregion
|
|
6015
|
+
//#region src/core/head.ts
|
|
6016
|
+
const headProperties = [
|
|
6017
|
+
"title",
|
|
6018
|
+
"meta",
|
|
6019
|
+
"link",
|
|
6020
|
+
"base",
|
|
6021
|
+
"style",
|
|
6022
|
+
"script",
|
|
6023
|
+
"htmlAttrs",
|
|
6024
|
+
"bodyAttrs"
|
|
6025
|
+
];
|
|
6026
|
+
function preprocessHead(frontmatter, options) {
|
|
6027
|
+
if (!options.headEnabled) return frontmatter;
|
|
6028
|
+
const head = options.headField ? frontmatter[options.headField] || {} : frontmatter;
|
|
6029
|
+
const meta = head.meta = head.meta || [];
|
|
6030
|
+
if (head.title) {
|
|
6031
|
+
if (!meta.some((i) => i.property === "og:title")) meta.push({
|
|
6032
|
+
property: "og:title",
|
|
6033
|
+
content: head.title
|
|
6034
|
+
});
|
|
6035
|
+
if (!meta.some((i) => i.name === "twitter:title")) meta.push({
|
|
6036
|
+
name: "twitter:title",
|
|
6037
|
+
content: head.title
|
|
6038
|
+
});
|
|
6039
|
+
}
|
|
6040
|
+
if (head.description) {
|
|
6041
|
+
if (!meta.some((i) => i.name === "description")) meta.push({
|
|
6042
|
+
name: "description",
|
|
6043
|
+
content: head.description
|
|
6044
|
+
});
|
|
6045
|
+
if (!meta.some((i) => i.property === "og:description")) meta.push({
|
|
6046
|
+
property: "og:description",
|
|
6047
|
+
content: head.description
|
|
6048
|
+
});
|
|
6049
|
+
if (!meta.some((i) => i.name === "twitter:description")) meta.push({
|
|
6050
|
+
name: "twitter:description",
|
|
6051
|
+
content: head.description
|
|
6052
|
+
});
|
|
6053
|
+
}
|
|
6054
|
+
if (head.image) {
|
|
6055
|
+
if (!meta.some((i) => i.property === "og:image")) meta.push({
|
|
6056
|
+
property: "og:image",
|
|
6057
|
+
content: head.image
|
|
6058
|
+
});
|
|
6059
|
+
if (!meta.some((i) => i.name === "twitter:image")) meta.push({
|
|
6060
|
+
name: "twitter:image",
|
|
6061
|
+
content: head.image
|
|
6062
|
+
});
|
|
6063
|
+
if (!meta.some((i) => i.property === "twitter:card")) meta.push({
|
|
6064
|
+
name: "twitter:card",
|
|
6065
|
+
content: "summary_large_image"
|
|
6066
|
+
});
|
|
6067
|
+
}
|
|
6068
|
+
const result = {};
|
|
6069
|
+
for (const [key, value] of Object.entries(head)) if (headProperties.includes(key)) result[key] = value;
|
|
6070
|
+
return Object.entries(result).length === 0 ? null : result;
|
|
6071
|
+
}
|
|
6072
|
+
//#endregion
|
|
6073
|
+
//#region src/core/markdown.ts
|
|
6074
|
+
const scriptSetupRE = /<\s*script([^>]*)\bsetup\b([^>]*)>([\s\S]*)<\/script>/g;
|
|
6075
|
+
const defineExposeRE = /defineExpose\s*\(/g;
|
|
6076
|
+
const EXPORTS_KEYWORDS = [
|
|
6077
|
+
"class",
|
|
6078
|
+
"default",
|
|
6079
|
+
"export",
|
|
6080
|
+
"function",
|
|
6081
|
+
"import",
|
|
6082
|
+
"let",
|
|
6083
|
+
"var",
|
|
6084
|
+
"const",
|
|
6085
|
+
"from",
|
|
6086
|
+
"as",
|
|
6087
|
+
"return",
|
|
6088
|
+
"if",
|
|
6089
|
+
"else",
|
|
6090
|
+
"switch",
|
|
6091
|
+
"case",
|
|
6092
|
+
"break",
|
|
6093
|
+
"for",
|
|
6094
|
+
"while",
|
|
6095
|
+
"do"
|
|
6096
|
+
];
|
|
6097
|
+
function extractScriptSetup(html) {
|
|
6098
|
+
const scripts = [];
|
|
6099
|
+
html = html.replace(scriptSetupRE, (_, attr1, attr2, code) => {
|
|
6100
|
+
scripts.push({
|
|
6101
|
+
code,
|
|
6102
|
+
attr: `${attr1} ${attr2}`.trim()
|
|
6103
|
+
});
|
|
6104
|
+
return "";
|
|
6105
|
+
});
|
|
6106
|
+
return {
|
|
6107
|
+
html,
|
|
6108
|
+
scripts
|
|
6109
|
+
};
|
|
6110
|
+
}
|
|
6111
|
+
function extractCustomBlock(html, options) {
|
|
6112
|
+
const blocks = [];
|
|
6113
|
+
for (const tag of options.customSfcBlocks) html = html.replace(new RegExp(`<${tag}[^>]*\\b[^>]*>[^<]*<\\/${tag}>`, "gm"), (code) => {
|
|
6114
|
+
blocks.push(code);
|
|
6115
|
+
return "";
|
|
6116
|
+
});
|
|
6117
|
+
return {
|
|
6118
|
+
html,
|
|
6119
|
+
blocks
|
|
6120
|
+
};
|
|
6121
|
+
}
|
|
6122
|
+
function createMarkdown(options) {
|
|
6123
|
+
const isVue2 = options.vueVersion.startsWith("2.");
|
|
6124
|
+
const setupPromise = (async () => {
|
|
6125
|
+
const md = createMarkdownExit({
|
|
6126
|
+
html: true,
|
|
6127
|
+
linkify: true,
|
|
6128
|
+
typographer: true,
|
|
6129
|
+
...options.markdownOptions
|
|
6130
|
+
});
|
|
6131
|
+
md.use(componentPlugin, options.componentOptions);
|
|
6132
|
+
if (options.frontmatter || options.excerpt) md.use(frontmatterPlugin, {
|
|
6133
|
+
...options.frontmatterOptions,
|
|
6134
|
+
grayMatterOptions: {
|
|
6135
|
+
excerpt: options.excerpt,
|
|
6136
|
+
...options.frontmatterOptions.grayMatterOptions
|
|
6137
|
+
}
|
|
6138
|
+
});
|
|
6139
|
+
md.linkify.set({ fuzzyLink: false });
|
|
6140
|
+
options.markdownUses.forEach((e) => {
|
|
6141
|
+
const [plugin, options] = toArray(e);
|
|
6142
|
+
md.use(plugin, options);
|
|
6143
|
+
});
|
|
6144
|
+
await options.markdownSetup(md);
|
|
6145
|
+
return md;
|
|
6146
|
+
})();
|
|
6147
|
+
return async (id, raw) => {
|
|
6148
|
+
const md = await setupPromise;
|
|
6149
|
+
const { wrapperDiv, wrapperClasses, wrapperComponent, transforms, headEnabled, frontmatterPreprocess } = options;
|
|
6150
|
+
raw = raw.trimStart();
|
|
6151
|
+
raw = await transforms.before?.(raw, id) ?? raw;
|
|
6152
|
+
const env = { id };
|
|
6153
|
+
let html = await md.renderAsync(raw, env);
|
|
6154
|
+
const { excerpt = "", frontmatter: data = null } = env;
|
|
6155
|
+
if (wrapperDiv) {
|
|
6156
|
+
const wrapperClassesResolved = toArray(typeof wrapperClasses === "function" ? wrapperClasses(id, raw) : wrapperClasses).filter(Boolean).join(" ");
|
|
6157
|
+
if (wrapperClassesResolved) html = `<div class="${wrapperClassesResolved}">${html}</div>`;
|
|
6158
|
+
else html = `<div>${html}</div>`;
|
|
6159
|
+
}
|
|
6160
|
+
const wrapperComponentName = typeof wrapperComponent === "function" ? wrapperComponent(id, raw) : wrapperComponent;
|
|
6161
|
+
if (wrapperComponentName) html = `<${wrapperComponentName} ${[options.frontmatter && ":frontmatter=\"frontmatter\"", options.excerpt && ":excerpt=\"excerpt\""].filter(Boolean).join(" ")}>${html}</${wrapperComponentName}>`;
|
|
6162
|
+
html = await transforms.after?.(html, id) ?? html;
|
|
6163
|
+
if (options.escapeCodeTagInterpolation) html = html.replace(/<code(.*?)>/g, "<code$1 v-pre>");
|
|
6164
|
+
const hoistScripts = extractScriptSetup(html);
|
|
6165
|
+
html = hoistScripts.html;
|
|
6166
|
+
const customBlocks = extractCustomBlock(html, options);
|
|
6167
|
+
html = customBlocks.html;
|
|
6168
|
+
const scriptLines = [];
|
|
6169
|
+
let frontmatterExportsLines = [];
|
|
6170
|
+
let excerptExportsLine = "";
|
|
6171
|
+
let excerptKeyOverlapping = false;
|
|
6172
|
+
function hasExplicitExports() {
|
|
6173
|
+
return defineExposeRE.test(hoistScripts.scripts.map((i) => i.code).join(""));
|
|
6174
|
+
}
|
|
6175
|
+
if (options.frontmatter) {
|
|
6176
|
+
if (options.excerpt && data) {
|
|
6177
|
+
if (data.excerpt !== void 0) excerptKeyOverlapping = true;
|
|
6178
|
+
data.excerpt = excerpt;
|
|
6179
|
+
}
|
|
6180
|
+
const { head, frontmatter } = frontmatterPreprocess(data || {}, options, id, preprocessHead);
|
|
6181
|
+
if (options.excerpt && !excerptKeyOverlapping && frontmatter.excerpt !== void 0) delete frontmatter.excerpt;
|
|
6182
|
+
scriptLines.push(`const frontmatter = ${JSON.stringify(frontmatter)}`);
|
|
6183
|
+
if (options.exportFrontmatter) frontmatterExportsLines = Object.entries(frontmatter).map(([key, value]) => {
|
|
6184
|
+
if (EXPORTS_KEYWORDS.includes(key)) key = `_${key}`;
|
|
6185
|
+
return `export const ${key} = ${JSON.stringify(value)}`;
|
|
6186
|
+
});
|
|
6187
|
+
if (!isVue2 && options.exposeFrontmatter && !hasExplicitExports()) scriptLines.push("defineExpose({ frontmatter })");
|
|
6188
|
+
if (!isVue2 && headEnabled && head) {
|
|
6189
|
+
if (headEnabled === "vueuse") throw new Error("unplugin-vue-markdown no longer supports @vueuse/head. Change `headEnabled` to `true` and install `@unhead/vue` instead.");
|
|
6190
|
+
scriptLines.push(`const head = ${JSON.stringify(head)}`);
|
|
6191
|
+
scriptLines.unshift(`import { useHead } from "@unhead/vue"`);
|
|
6192
|
+
scriptLines.push("useHead(head)");
|
|
6193
|
+
}
|
|
6194
|
+
scriptLines.push(...await transforms.extraScripts?.(frontmatter, id) || []);
|
|
6195
|
+
}
|
|
6196
|
+
if (options.excerpt) {
|
|
6197
|
+
scriptLines.push(`const excerpt = ${JSON.stringify(excerpt)}`);
|
|
6198
|
+
if (!excerptKeyOverlapping) excerptExportsLine = `export const excerpt = ${JSON.stringify(excerpt)}\n`;
|
|
6199
|
+
if (!isVue2 && options.exposeExcerpt && !hasExplicitExports()) scriptLines.push("defineExpose({ excerpt })");
|
|
6200
|
+
}
|
|
6201
|
+
scriptLines.push(...hoistScripts.scripts.map((i) => i.code));
|
|
6202
|
+
let attrs = uniq(hoistScripts.scripts.map((i) => i.attr)).join(" ").trim();
|
|
6203
|
+
if (attrs) attrs = ` ${attrs}`;
|
|
6204
|
+
const scripts = isVue2 ? [
|
|
6205
|
+
`<script${attrs}>`,
|
|
6206
|
+
...scriptLines,
|
|
6207
|
+
...frontmatterExportsLines,
|
|
6208
|
+
excerptExportsLine,
|
|
6209
|
+
"export default { data() { return { frontmatter } } }",
|
|
6210
|
+
"<\/script>"
|
|
6211
|
+
] : [
|
|
6212
|
+
`<script setup${attrs}>`,
|
|
6213
|
+
...scriptLines,
|
|
6214
|
+
"<\/script>",
|
|
6215
|
+
...frontmatterExportsLines.length || excerptExportsLine ? [
|
|
6216
|
+
`<script${attrs}>`,
|
|
6217
|
+
...frontmatterExportsLines,
|
|
6218
|
+
excerptExportsLine,
|
|
6219
|
+
"<\/script>"
|
|
6220
|
+
] : []
|
|
6221
|
+
];
|
|
6222
|
+
return {
|
|
6223
|
+
code: [
|
|
6224
|
+
`<template>${html}</template>`,
|
|
6225
|
+
...scripts.map((i) => i.trim()).filter(Boolean),
|
|
6226
|
+
...customBlocks.blocks
|
|
6227
|
+
].join("\n"),
|
|
6228
|
+
map: { mappings: "" }
|
|
6229
|
+
};
|
|
6230
|
+
};
|
|
6231
|
+
}
|
|
6232
|
+
//#endregion
|
|
6233
|
+
//#region src/core/utils.ts
|
|
6234
|
+
const _require = typeof __require === "undefined" ? createRequire(import.meta.url) : __require;
|
|
6235
|
+
function getVueVersion(defaultVersion = "3.2.0") {
|
|
6236
|
+
try {
|
|
6237
|
+
let v = _require("vue");
|
|
6238
|
+
if (v.default) v = v.default;
|
|
6239
|
+
return v.version || defaultVersion;
|
|
6240
|
+
} catch {
|
|
6241
|
+
return defaultVersion;
|
|
6242
|
+
}
|
|
6243
|
+
}
|
|
6244
|
+
//#endregion
|
|
6245
|
+
//#region src/core/options.ts
|
|
6246
|
+
function resolveOptions(userOptions) {
|
|
6247
|
+
const noop = () => {};
|
|
6248
|
+
const markdownOptions = userOptions.markdownOptions ?? userOptions.markdownItOptions ?? {};
|
|
6249
|
+
const markdownUses = userOptions.markdownUses ?? userOptions.markdownItUses ?? [];
|
|
6250
|
+
const markdownSetup = userOptions.markdownSetup ?? userOptions.markdownItSetup ?? noop;
|
|
6251
|
+
return {
|
|
6252
|
+
headEnabled: false,
|
|
6253
|
+
headField: "",
|
|
6254
|
+
frontmatter: true,
|
|
6255
|
+
excerpt: false,
|
|
6256
|
+
exposeFrontmatter: true,
|
|
6257
|
+
exposeExcerpt: false,
|
|
6258
|
+
exportFrontmatter: true,
|
|
6259
|
+
escapeCodeTagInterpolation: true,
|
|
6260
|
+
customSfcBlocks: [
|
|
6261
|
+
"route",
|
|
6262
|
+
"i18n",
|
|
6263
|
+
"style"
|
|
6264
|
+
],
|
|
6265
|
+
componentOptions: {},
|
|
6266
|
+
frontmatterOptions: {},
|
|
6267
|
+
markdownOptions: {},
|
|
6268
|
+
markdownUses: [],
|
|
6269
|
+
markdownSetup: noop,
|
|
6270
|
+
markdownItOptions: {},
|
|
6271
|
+
markdownItUses: [],
|
|
6272
|
+
markdownItSetup: noop,
|
|
6273
|
+
wrapperDiv: true,
|
|
6274
|
+
wrapperComponent: null,
|
|
6275
|
+
transforms: {},
|
|
6276
|
+
vueVersion: userOptions.vueVersion || getVueVersion(),
|
|
6277
|
+
wrapperClasses: "markdown-body",
|
|
6278
|
+
include: null,
|
|
6279
|
+
exclude: null,
|
|
6280
|
+
frontmatterPreprocess: (frontmatter, options, _id, defaults) => {
|
|
6281
|
+
return {
|
|
6282
|
+
head: defaults(frontmatter, options),
|
|
6283
|
+
frontmatter
|
|
6284
|
+
};
|
|
6285
|
+
},
|
|
6286
|
+
...userOptions,
|
|
6287
|
+
markdownOptions,
|
|
6288
|
+
markdownUses,
|
|
6289
|
+
markdownSetup,
|
|
6290
|
+
markdownItOptions: markdownOptions,
|
|
6291
|
+
markdownItUses: markdownUses,
|
|
6292
|
+
markdownItSetup: markdownSetup
|
|
6293
|
+
};
|
|
6294
|
+
}
|
|
6295
|
+
//#endregion
|
|
6296
|
+
//#region src/index.ts
|
|
6297
|
+
const cssIdRE = /\.(css|postcss|sass|scss|less|stylus|styl)($|\?)/;
|
|
6298
|
+
const unpluginFactory = (userOptions = {}) => {
|
|
6299
|
+
const markdownToVue = createMarkdown(resolveOptions(userOptions));
|
|
6300
|
+
const filter = createFilter(userOptions.include || /\.md$|\.md\?vue/, userOptions.exclude || cssIdRE);
|
|
6301
|
+
return {
|
|
6302
|
+
name: "unplugin-vue-markdown",
|
|
6303
|
+
enforce: "pre",
|
|
6304
|
+
transformInclude(id) {
|
|
6305
|
+
return filter(id);
|
|
6306
|
+
},
|
|
6307
|
+
async transform(raw, id) {
|
|
6308
|
+
if (id.includes("?vue&type=")) return null;
|
|
6309
|
+
try {
|
|
6310
|
+
return await markdownToVue(id, raw);
|
|
6311
|
+
} catch (e) {
|
|
6312
|
+
this.error(e);
|
|
6313
|
+
}
|
|
6314
|
+
},
|
|
6315
|
+
vite: { async handleHotUpdate(ctx) {
|
|
6316
|
+
if (!filter(ctx.file)) return;
|
|
6317
|
+
const defaultRead = ctx.read;
|
|
6318
|
+
ctx.read = async function() {
|
|
6319
|
+
return (await markdownToVue(ctx.file, await defaultRead())).code;
|
|
6320
|
+
};
|
|
6321
|
+
} }
|
|
6322
|
+
};
|
|
6323
|
+
};
|
|
6324
|
+
|
|
6325
|
+
//#region src/vite.ts
|
|
6326
|
+
var vite_default = createVitePlugin(unpluginFactory);
|
|
6327
|
+
|
|
5476
6328
|
function cacheMarkdownRender(md, state, base, fileInfoFor) {
|
|
5477
6329
|
const cache = new LRUCache({
|
|
5478
6330
|
max: 2048,
|
|
@@ -5585,8 +6437,6 @@ function disposeMdItInstance() {
|
|
|
5585
6437
|
Valaxy.state.dispose();
|
|
5586
6438
|
}
|
|
5587
6439
|
async function createMarkdownPlugin(options, base, state = Valaxy.state) {
|
|
5588
|
-
await ensureGrayMatterRedirect();
|
|
5589
|
-
const { default: Markdown } = await import('unplugin-vue-markdown/vite');
|
|
5590
6440
|
const mdOptions = options?.config.markdown || {};
|
|
5591
6441
|
const theme = mdOptions.theme ?? defaultCodeTheme;
|
|
5592
6442
|
const transformIncludes = createTransformIncludes(options);
|
|
@@ -5595,17 +6445,32 @@ async function createMarkdownPlugin(options, base, state = Valaxy.state) {
|
|
|
5595
6445
|
state.onDispose(dispose);
|
|
5596
6446
|
const {
|
|
5597
6447
|
transforms: userTransforms,
|
|
6448
|
+
frontmatterPreprocess: userFrontmatterPreprocess,
|
|
5598
6449
|
markdownSetup: userMarkdownSetup,
|
|
5599
6450
|
markdownItSetup: userMarkdownItSetup,
|
|
5600
6451
|
...restMdOptions
|
|
5601
6452
|
} = mdOptions;
|
|
5602
6453
|
const setupUserMarkdown = userMarkdownSetup ?? userMarkdownItSetup;
|
|
5603
|
-
return
|
|
6454
|
+
return vite_default({
|
|
5604
6455
|
include: [/\.md$/],
|
|
5605
6456
|
wrapperClasses: "",
|
|
5606
6457
|
// headEnabled: false,
|
|
5607
6458
|
frontmatter: true,
|
|
5608
6459
|
exportFrontmatter: false,
|
|
6460
|
+
frontmatterPreprocess(frontmatter, markdownOptions, id, defaultHeadProcess) {
|
|
6461
|
+
const publicFrontmatter = { ...frontmatter };
|
|
6462
|
+
if (options.config.siteConfig.encrypt?.enable) {
|
|
6463
|
+
delete publicFrontmatter.password;
|
|
6464
|
+
if (publicFrontmatter.gallery_password) {
|
|
6465
|
+
delete publicFrontmatter.gallery_password;
|
|
6466
|
+
delete publicFrontmatter.photos;
|
|
6467
|
+
}
|
|
6468
|
+
}
|
|
6469
|
+
return userFrontmatterPreprocess?.(publicFrontmatter, markdownOptions, id, defaultHeadProcess) ?? {
|
|
6470
|
+
head: defaultHeadProcess(publicFrontmatter, markdownOptions),
|
|
6471
|
+
frontmatter: publicFrontmatter
|
|
6472
|
+
};
|
|
6473
|
+
},
|
|
5609
6474
|
frontmatterOptions: {
|
|
5610
6475
|
// Disable excerpt rendering in @mdit-vue/plugin-frontmatter because it
|
|
5611
6476
|
// uses sync md.render() which throws with async highlight (markdown-exit:
|
|
@@ -5743,12 +6608,17 @@ async function localSearchPlugin(options, base) {
|
|
|
5743
6608
|
if (!fs.existsSync(file))
|
|
5744
6609
|
return { html: "", shared: false };
|
|
5745
6610
|
const relativePath = getPagePath(file, options.userRoot) || slash$1(path.relative(srcDir, file));
|
|
6611
|
+
if (isUnpublishedPage(relativePath, siteConfig.publishing))
|
|
6612
|
+
return { html: "", shared: false };
|
|
5746
6613
|
const env = { path: file, relativePath };
|
|
5747
6614
|
const mdRaw = await fs.promises.readFile(file, "utf-8");
|
|
5748
|
-
const { data
|
|
5749
|
-
const
|
|
6615
|
+
const { data, content } = matter(mdRaw, matterOptions);
|
|
6616
|
+
const fm = { ...siteConfig.frontmatter, ...data };
|
|
6617
|
+
if (fm.search === false || fm.draft && !siteConfig.publishing?.drafts || fm.hide || fm.password || fm.encrypt === true)
|
|
6618
|
+
return { html: "", shared: false };
|
|
6619
|
+
const mdSrc = stripEncryptedContent(processIncludes(srcDir, stripEncryptedContent(content), file));
|
|
5750
6620
|
const html = await md.renderAsync(mdSrc, env);
|
|
5751
|
-
return { html
|
|
6621
|
+
return { html, shared: fm.sharedLocale === true };
|
|
5752
6622
|
}
|
|
5753
6623
|
const indexByLocales = /* @__PURE__ */ new Map();
|
|
5754
6624
|
const fileToDocIds = /* @__PURE__ */ new Map();
|
|
@@ -5827,7 +6697,7 @@ async function localSearchPlugin(options, base) {
|
|
|
5827
6697
|
}
|
|
5828
6698
|
fileToDocIds.set(page, { locales, ids: docIds });
|
|
5829
6699
|
}
|
|
5830
|
-
function discardFile(page) {
|
|
6700
|
+
async function discardFile(page) {
|
|
5831
6701
|
const entry = fileToDocIds.get(page);
|
|
5832
6702
|
if (!entry)
|
|
5833
6703
|
return true;
|
|
@@ -5844,6 +6714,7 @@ async function localSearchPlugin(options, base) {
|
|
|
5844
6714
|
}
|
|
5845
6715
|
}
|
|
5846
6716
|
}
|
|
6717
|
+
await Promise.all(entry.locales.map((locale) => indexByLocales.get(locale)?.vacuum()));
|
|
5847
6718
|
fileToDocIds.delete(page);
|
|
5848
6719
|
return true;
|
|
5849
6720
|
}
|
|
@@ -5865,7 +6736,7 @@ async function localSearchPlugin(options, base) {
|
|
|
5865
6736
|
changedPages.clear();
|
|
5866
6737
|
pendingUpdate = pendingUpdate.catch((error) => server?.config.logger.error(String(error))).then(async () => {
|
|
5867
6738
|
for (const page of pages) {
|
|
5868
|
-
if (!discardFile(page)) {
|
|
6739
|
+
if (!await discardFile(page)) {
|
|
5869
6740
|
await scanForBuild();
|
|
5870
6741
|
break;
|
|
5871
6742
|
}
|
|
@@ -6168,6 +7039,85 @@ function transformHexoTags(code, id) {
|
|
|
6168
7039
|
return code;
|
|
6169
7040
|
}
|
|
6170
7041
|
|
|
7042
|
+
function getHeadMetaContent(head, name) {
|
|
7043
|
+
if (!head || !head.length)
|
|
7044
|
+
return void 0;
|
|
7045
|
+
const meta = head.find(([tag, attrs = {}]) => {
|
|
7046
|
+
return tag === "meta" && attrs.name === name && attrs.content;
|
|
7047
|
+
});
|
|
7048
|
+
return meta && meta[1].content;
|
|
7049
|
+
}
|
|
7050
|
+
function inferDescription(frontmatter) {
|
|
7051
|
+
const { description, head } = frontmatter;
|
|
7052
|
+
if (description !== void 0)
|
|
7053
|
+
return description;
|
|
7054
|
+
return head && getHeadMetaContent(head, "description") || "";
|
|
7055
|
+
}
|
|
7056
|
+
function extractFirstImage(code) {
|
|
7057
|
+
return extractMarkdownImage(code);
|
|
7058
|
+
}
|
|
7059
|
+
function filterPublicHeaders(headers, publicHeadingIds) {
|
|
7060
|
+
return headers.flatMap((header) => {
|
|
7061
|
+
const children = header.children ? filterPublicHeaders(header.children, publicHeadingIds) : [];
|
|
7062
|
+
if (!publicHeadingIds.has(header.slug))
|
|
7063
|
+
return children;
|
|
7064
|
+
return [{ ...header, ...header.children ? { children } : {} }];
|
|
7065
|
+
});
|
|
7066
|
+
}
|
|
7067
|
+
async function generatePageData(code, context, options) {
|
|
7068
|
+
const { id, fileInfo } = context;
|
|
7069
|
+
const relativePath = path$1.relative(options.userRoot, id);
|
|
7070
|
+
const fm = fileInfo?.frontmatter ? JSON.parse(JSON.stringify(fileInfo.frontmatter)) : {};
|
|
7071
|
+
if (options.config.features?.extractFirstImage !== false && !fm.password && fm.encrypt !== true && !pickPageShareImage(fm)) {
|
|
7072
|
+
const firstImage = extractFirstImage(code);
|
|
7073
|
+
if (firstImage)
|
|
7074
|
+
fm.firstImage = firstImage;
|
|
7075
|
+
}
|
|
7076
|
+
const isPrivate = !!fm.password || fm.encrypt === true;
|
|
7077
|
+
const publicCode = stripEncryptedContent(code);
|
|
7078
|
+
const hasPrivateContent = isPrivate || publicCode !== code;
|
|
7079
|
+
const publicHeadingIds = new Set(Array.from(publicCode.matchAll(/<h[1-6]\s[^>]*\bid=["']([^"']+)["'][^>]*>/g), (match) => match[1]));
|
|
7080
|
+
const publicHeaders = filterPublicHeaders(fileInfo?.headers || [], publicHeadingIds);
|
|
7081
|
+
const firstHeading = code.match(/<h1\b[^>]*>[\s\S]*?<\/h1>/)?.[0];
|
|
7082
|
+
const hasPublicTitle = !isPrivate && (!hasPrivateContent || firstHeading && publicCode.includes(firstHeading));
|
|
7083
|
+
const pageData = {
|
|
7084
|
+
title: fm.title || hasPublicTitle && fileInfo?.title || "",
|
|
7085
|
+
titleTemplate: fm.titleTemplate,
|
|
7086
|
+
description: inferDescription(fm),
|
|
7087
|
+
frontmatter: fm,
|
|
7088
|
+
// not be used
|
|
7089
|
+
headers: isPrivate ? [] : hasPrivateContent ? publicHeaders : fileInfo?.headers || [],
|
|
7090
|
+
relativePath,
|
|
7091
|
+
filePath: id
|
|
7092
|
+
};
|
|
7093
|
+
if (options.config.siteConfig.lastUpdated && fm.lastUpdated !== false)
|
|
7094
|
+
pageData.lastUpdated = await getGitTimestamp(id);
|
|
7095
|
+
return pageData;
|
|
7096
|
+
}
|
|
7097
|
+
function resolvePageImageImports(frontmatter, id) {
|
|
7098
|
+
const imports = [];
|
|
7099
|
+
const assignments = [];
|
|
7100
|
+
for (const key of ["ogImage", "image", "cover", "firstImage"]) {
|
|
7101
|
+
const src = pickShareImage([frontmatter[key]]);
|
|
7102
|
+
if (!src || src.startsWith("/") || /^[a-z][\w+.-]*:/i.test(src))
|
|
7103
|
+
continue;
|
|
7104
|
+
const [urlPath] = src.split(/[?#]/);
|
|
7105
|
+
const suffix = src.slice(urlPath.length);
|
|
7106
|
+
let filename = urlPath;
|
|
7107
|
+
try {
|
|
7108
|
+
filename = decodeURI(urlPath);
|
|
7109
|
+
} catch {
|
|
7110
|
+
}
|
|
7111
|
+
if (!existsSync(path$1.resolve(path$1.dirname(id), filename)))
|
|
7112
|
+
continue;
|
|
7113
|
+
const name = `__valaxy_${key}`;
|
|
7114
|
+
const request = `${filename.startsWith(".") ? filename : `./${filename}`}?url&no-inline`;
|
|
7115
|
+
imports.push(`import ${name} from ${JSON.stringify(request)}`);
|
|
7116
|
+
assignments.push(`pageData.value.frontmatter.${key} = ${name} + ${JSON.stringify(suffix)}`);
|
|
7117
|
+
}
|
|
7118
|
+
return { imports, assignments };
|
|
7119
|
+
}
|
|
7120
|
+
|
|
6171
7121
|
function genProvideCode(name, data) {
|
|
6172
7122
|
return [
|
|
6173
7123
|
`const $${name} = ${transformObject(data)}`,
|
|
@@ -6176,13 +7126,16 @@ function genProvideCode(name, data) {
|
|
|
6176
7126
|
];
|
|
6177
7127
|
}
|
|
6178
7128
|
const encryptedKeys = ["encryptedContent", "partiallyEncryptedContents", "encryptedPhotos"];
|
|
6179
|
-
function injectPageDataCode(pageData) {
|
|
7129
|
+
function injectPageDataCode(pageData, id) {
|
|
7130
|
+
const images = id ? resolvePageImageImports(pageData.frontmatter, id) : { imports: [], assignments: [] };
|
|
6180
7131
|
const staticPageData = transformObject(pageData);
|
|
6181
7132
|
const vueContextImports = [
|
|
6182
7133
|
`import { provide, shallowRef } from 'vue'`,
|
|
6183
7134
|
`import { useRoute, useRouter } from 'vue-router'`,
|
|
7135
|
+
...images.imports,
|
|
6184
7136
|
// Use static page data instead of data loader
|
|
6185
7137
|
`const pageData = shallowRef(${staticPageData})`,
|
|
7138
|
+
...images.assignments,
|
|
6186
7139
|
"const router = useRouter()",
|
|
6187
7140
|
"const route = useRoute()",
|
|
6188
7141
|
// $frontmatter contain runtime added data, will be deleted (for example, $frontmatter.partiallyEncryptedContents)
|
|
@@ -6205,7 +7158,7 @@ function createTransformMarkdown(options) {
|
|
|
6205
7158
|
if (!isDev) {
|
|
6206
7159
|
delete pageData.filePath;
|
|
6207
7160
|
}
|
|
6208
|
-
const dataCode = injectPageDataCode(pageData);
|
|
7161
|
+
const dataCode = injectPageDataCode(pageData, id);
|
|
6209
7162
|
const imports = [
|
|
6210
7163
|
...dataCode,
|
|
6211
7164
|
isDev ? `globalThis.$pageData = pageData` : "",
|
|
@@ -6234,53 +7187,6 @@ ${code.slice(injectB)}`;
|
|
|
6234
7187
|
};
|
|
6235
7188
|
}
|
|
6236
7189
|
|
|
6237
|
-
function getHeadMetaContent(head, name) {
|
|
6238
|
-
if (!head || !head.length)
|
|
6239
|
-
return void 0;
|
|
6240
|
-
const meta = head.find(([tag, attrs = {}]) => {
|
|
6241
|
-
return tag === "meta" && attrs.name === name && attrs.content;
|
|
6242
|
-
});
|
|
6243
|
-
return meta && meta[1].content;
|
|
6244
|
-
}
|
|
6245
|
-
function inferDescription(frontmatter) {
|
|
6246
|
-
const { description, head } = frontmatter;
|
|
6247
|
-
if (description !== void 0)
|
|
6248
|
-
return description;
|
|
6249
|
-
return head && getHeadMetaContent(head, "description") || "";
|
|
6250
|
-
}
|
|
6251
|
-
function extractFirstImage(code) {
|
|
6252
|
-
const mdImageMatch = code.match(/!\[.*?\]\((.+?)\)/);
|
|
6253
|
-
if (mdImageMatch)
|
|
6254
|
-
return mdImageMatch[1];
|
|
6255
|
-
const htmlImageMatch = code.match(/<img\s[^>]*?src=["'](.+?)["']/);
|
|
6256
|
-
if (htmlImageMatch)
|
|
6257
|
-
return htmlImageMatch[1];
|
|
6258
|
-
return void 0;
|
|
6259
|
-
}
|
|
6260
|
-
async function generatePageData(code, context, options) {
|
|
6261
|
-
const { id, fileInfo } = context;
|
|
6262
|
-
const relativePath = path$1.relative(options.userRoot, id);
|
|
6263
|
-
const fm = fileInfo?.frontmatter ? JSON.parse(JSON.stringify(fileInfo.frontmatter)) : {};
|
|
6264
|
-
if (options.config.features?.extractFirstImage !== false && !fm.ogImage && !fm.cover) {
|
|
6265
|
-
const firstImage = extractFirstImage(code);
|
|
6266
|
-
if (firstImage)
|
|
6267
|
-
fm.firstImage = firstImage;
|
|
6268
|
-
}
|
|
6269
|
-
const pageData = {
|
|
6270
|
-
title: fm.title || fileInfo?.title || "",
|
|
6271
|
-
titleTemplate: fm.titleTemplate,
|
|
6272
|
-
description: inferDescription(fm),
|
|
6273
|
-
frontmatter: fm,
|
|
6274
|
-
// not be used
|
|
6275
|
-
headers: fileInfo?.headers || [],
|
|
6276
|
-
relativePath,
|
|
6277
|
-
filePath: id
|
|
6278
|
-
};
|
|
6279
|
-
if (options.config.siteConfig.lastUpdated && fm.lastUpdated !== false)
|
|
6280
|
-
pageData.lastUpdated = await getGitTimestamp(id);
|
|
6281
|
-
return pageData;
|
|
6282
|
-
}
|
|
6283
|
-
|
|
6284
7190
|
const debug = _debug("valaxy:md");
|
|
6285
7191
|
const caches = /* @__PURE__ */ new WeakMap();
|
|
6286
7192
|
function getMarkdownCache(state) {
|
|
@@ -6360,6 +7266,7 @@ async function createMarkdownToVueRenderFn(options, state = Valaxy.state) {
|
|
|
6360
7266
|
const includes = data.includes;
|
|
6361
7267
|
code = data.code;
|
|
6362
7268
|
code = transformCodeBlock(code, context);
|
|
7269
|
+
const hasPrivateSource = !!(pageData.frontmatter.password || pageData.frontmatter.encrypt || pageData.frontmatter.gallery_password || code.includes("valaxy-encrypt-start:"));
|
|
6363
7270
|
code = await transformEncrypt(code, id, pageData);
|
|
6364
7271
|
code = transformFootnoteTooltip(code);
|
|
6365
7272
|
code = transformMarkdown(code, id, pageData);
|
|
@@ -6368,7 +7275,8 @@ async function createMarkdownToVueRenderFn(options, state = Valaxy.state) {
|
|
|
6368
7275
|
code,
|
|
6369
7276
|
pageData,
|
|
6370
7277
|
deadLinks,
|
|
6371
|
-
includes
|
|
7278
|
+
includes,
|
|
7279
|
+
hasPrivateSource
|
|
6372
7280
|
};
|
|
6373
7281
|
if (isBuild)
|
|
6374
7282
|
cache.set(cacheKey, result);
|
|
@@ -6399,7 +7307,7 @@ function createClientSetupPlugin(options) {
|
|
|
6399
7307
|
const name = id.slice(setupEntry.length + 1).replace(/\?.*$/, "");
|
|
6400
7308
|
const imports = [];
|
|
6401
7309
|
const injections = [];
|
|
6402
|
-
const setups = uniq([
|
|
7310
|
+
const setups = uniq$1([
|
|
6403
7311
|
themeRoot,
|
|
6404
7312
|
userRoot
|
|
6405
7313
|
]).map((i) => join(i, "setup", name));
|
|
@@ -6722,6 +7630,8 @@ async function createValaxyPlugin(options, serverOptions = {}, state = Valaxy.st
|
|
|
6722
7630
|
let { config: valaxyConfig } = options;
|
|
6723
7631
|
const valaxyPrefix = "/@valaxy";
|
|
6724
7632
|
let hasDeadLinks = false;
|
|
7633
|
+
const protectedMarkdown = /* @__PURE__ */ new Set();
|
|
7634
|
+
const protectedSourceAliases = /* @__PURE__ */ new Set();
|
|
6725
7635
|
let markdownToVue;
|
|
6726
7636
|
return [
|
|
6727
7637
|
{
|
|
@@ -6777,7 +7687,7 @@ async function createValaxyPlugin(options, serverOptions = {}, state = Valaxy.st
|
|
|
6777
7687
|
},
|
|
6778
7688
|
async transform(code, id) {
|
|
6779
7689
|
if (id.endsWith(".md")) {
|
|
6780
|
-
const { code: newCode, deadLinks, includes } = await markdownToVue(code, id);
|
|
7690
|
+
const { code: newCode, deadLinks, includes, hasPrivateSource } = await markdownToVue(code, id);
|
|
6781
7691
|
if (deadLinks.length) {
|
|
6782
7692
|
hasDeadLinks = true;
|
|
6783
7693
|
consola.error(`Dead links found in ${id}`);
|
|
@@ -6788,6 +7698,10 @@ async function createValaxyPlugin(options, serverOptions = {}, state = Valaxy.st
|
|
|
6788
7698
|
this.addWatchFile(i);
|
|
6789
7699
|
});
|
|
6790
7700
|
}
|
|
7701
|
+
if (hasPrivateSource) {
|
|
7702
|
+
protectedMarkdown.add(resolve$1(id));
|
|
7703
|
+
includes.forEach((file) => protectedMarkdown.add(resolve$1(file)));
|
|
7704
|
+
}
|
|
6791
7705
|
return newCode;
|
|
6792
7706
|
}
|
|
6793
7707
|
},
|
|
@@ -6813,7 +7727,7 @@ async function createValaxyPlugin(options, serverOptions = {}, state = Valaxy.st
|
|
|
6813
7727
|
};
|
|
6814
7728
|
const configFiles = [options.configFile, options.siteConfigFile, resolve$1(options.themeRoot, "valaxy.config.ts")];
|
|
6815
7729
|
if (configFiles.includes(file)) {
|
|
6816
|
-
const { config } = await resolveOptions$
|
|
7730
|
+
const { config } = await resolveOptions$2({ userRoot: options.userRoot });
|
|
6817
7731
|
return reloadConfigAndEntries(config);
|
|
6818
7732
|
}
|
|
6819
7733
|
if (file === options.themeConfigFile) {
|
|
@@ -6842,6 +7756,54 @@ async function createValaxyPlugin(options, serverOptions = {}, state = Valaxy.st
|
|
|
6842
7756
|
}
|
|
6843
7757
|
}
|
|
6844
7758
|
},
|
|
7759
|
+
{
|
|
7760
|
+
name: "valaxy:private-sourcemaps",
|
|
7761
|
+
enforce: "post",
|
|
7762
|
+
outputOptions(output) {
|
|
7763
|
+
const transformPath = output.sourcemapPathTransform;
|
|
7764
|
+
if (!transformPath)
|
|
7765
|
+
return;
|
|
7766
|
+
return {
|
|
7767
|
+
...output,
|
|
7768
|
+
sourcemapPathTransform(source, sourcemapPath) {
|
|
7769
|
+
const transformed = transformPath(source, sourcemapPath);
|
|
7770
|
+
if (protectedMarkdown.has(resolve$1(dirname$1(sourcemapPath), source.split("?")[0])))
|
|
7771
|
+
protectedSourceAliases.add(transformed.replaceAll("\\", "/"));
|
|
7772
|
+
return transformed;
|
|
7773
|
+
}
|
|
7774
|
+
};
|
|
7775
|
+
},
|
|
7776
|
+
generateBundle: {
|
|
7777
|
+
order: "post",
|
|
7778
|
+
handler(outputOptions, bundle) {
|
|
7779
|
+
if (!protectedMarkdown.size)
|
|
7780
|
+
return;
|
|
7781
|
+
const outputDir = outputOptions.dir || dirname$1(outputOptions.file || ".");
|
|
7782
|
+
const sanitize = (map, fileName) => {
|
|
7783
|
+
map.sourcesContent?.forEach((_content, index, contents) => {
|
|
7784
|
+
const source = map.sources?.[index];
|
|
7785
|
+
if (source && (protectedSourceAliases.has(source.replaceAll("\\", "/")) || protectedMarkdown.has(resolve$1(outputDir, dirname$1(fileName), map.sourceRoot || "", source.split("?")[0]))))
|
|
7786
|
+
contents[index] = null;
|
|
7787
|
+
});
|
|
7788
|
+
};
|
|
7789
|
+
for (const output of Object.values(bundle)) {
|
|
7790
|
+
if (output.type === "asset" && output.fileName.endsWith(".map")) {
|
|
7791
|
+
const map = JSON.parse(typeof output.source === "string" ? output.source : Buffer$1.from(output.source).toString());
|
|
7792
|
+
sanitize(map, output.fileName);
|
|
7793
|
+
output.source = JSON.stringify(map);
|
|
7794
|
+
} else if (output.type === "chunk") {
|
|
7795
|
+
if (output.map)
|
|
7796
|
+
sanitize(output.map, output.fileName);
|
|
7797
|
+
output.code = output.code.replace(/(\/\/[#@] sourceMappingURL=data:application\/json[^,]*;base64,)(\S+)/g, (_match, prefix, encoded) => {
|
|
7798
|
+
const map = JSON.parse(Buffer$1.from(encoded, "base64").toString());
|
|
7799
|
+
sanitize(map, output.fileName);
|
|
7800
|
+
return prefix + Buffer$1.from(JSON.stringify(map)).toString("base64");
|
|
7801
|
+
});
|
|
7802
|
+
}
|
|
7803
|
+
}
|
|
7804
|
+
}
|
|
7805
|
+
}
|
|
7806
|
+
},
|
|
6845
7807
|
{
|
|
6846
7808
|
name: "valaxy:state-cleanup",
|
|
6847
7809
|
enforce: "post",
|
|
@@ -6921,18 +7883,31 @@ async function createRouterOptions(valaxyApp, base, parseMatter = (source) => ma
|
|
|
6921
7883
|
// vue-router defaults to `watch: !process.env.CI`, which is true locally.
|
|
6922
7884
|
watch: options.mode !== "build",
|
|
6923
7885
|
...valaxyConfig.router,
|
|
7886
|
+
// Defaults stay in front of a user exclude list. `publishing` turns a class back on.
|
|
7887
|
+
exclude: mergePageExcludes(valaxyConfig.siteConfig.publishing, valaxyConfig.router?.exclude),
|
|
6924
7888
|
/**
|
|
6925
7889
|
* @experimental See https://github.com/posva/unplugin-vue-router/issues/43 (now part of vue-router)
|
|
6926
7890
|
* we need get frontmatter before route, so write it in extendRoute
|
|
6927
7891
|
*/
|
|
6928
7892
|
async extendRoute(route) {
|
|
7893
|
+
const publishing = valaxyConfig.siteConfig.publishing;
|
|
7894
|
+
const component = route.components?.get?.("default") || "";
|
|
7895
|
+
const relative = component ? relativePagePath(component, options.userRoot) || relativePagePath(component) : void 0;
|
|
7896
|
+
const privateSegment = route.fullPath.split("/").some((segment) => segment.startsWith("_"));
|
|
7897
|
+
const readmeMarkdown = isReadmePage(component);
|
|
7898
|
+
if (relative && isUnpublishedPage(relative, publishing) || !publishing?.underscore && privateSegment || !publishing?.readme && readmeMarkdown) {
|
|
7899
|
+
route.delete?.();
|
|
7900
|
+
return;
|
|
7901
|
+
}
|
|
6929
7902
|
if (valaxyConfig.siteConfig.frontmatter !== _lastFrontmatterRef) {
|
|
6930
7903
|
_lastFrontmatterRef = valaxyConfig.siteConfig.frontmatter;
|
|
6931
7904
|
_cachedFrontmatter = structuredClone(valaxyConfig.siteConfig.frontmatter);
|
|
6932
7905
|
}
|
|
6933
7906
|
const defaultFrontmatter = structuredClone(_cachedFrontmatter);
|
|
7907
|
+
const defaultPassword = defaultFrontmatter.password;
|
|
7908
|
+
delete defaultFrontmatter.password;
|
|
6934
7909
|
if (route.meta && route.meta.frontmatter) {
|
|
6935
|
-
const { frontmatter: _, ...otherMeta } = route.meta;
|
|
7910
|
+
const { frontmatter: _, seoDescription: _seoDescription, ...otherMeta } = route.meta;
|
|
6936
7911
|
route.meta = otherMeta;
|
|
6937
7912
|
}
|
|
6938
7913
|
route.addToMeta({
|
|
@@ -6970,6 +7945,9 @@ async function createRouterOptions(valaxyApp, base, parseMatter = (source) => ma
|
|
|
6970
7945
|
const { data, excerpt, content } = parseMatter(md);
|
|
6971
7946
|
const mdFm = data;
|
|
6972
7947
|
const lastUpdated = valaxyConfig.siteConfig.lastUpdated;
|
|
7948
|
+
const encrypted = Boolean(mdFm.password === void 0 ? defaultPassword : mdFm.password) || (mdFm.encrypt ?? defaultFrontmatter.encrypt) === true;
|
|
7949
|
+
const publicContent = encrypted ? "" : stripEncryptedContent(content);
|
|
7950
|
+
const publicExcerpt = publicContent.includes(EXCERPT_SEPARATOR) ? publicContent.split(EXCERPT_SEPARATOR)[0] : "";
|
|
6973
7951
|
delete mdFm.password;
|
|
6974
7952
|
if (mdFm.gallery_password) {
|
|
6975
7953
|
delete mdFm.gallery_password;
|
|
@@ -7017,16 +7995,22 @@ async function createRouterOptions(valaxyApp, base, parseMatter = (source) => ma
|
|
|
7017
7995
|
excludeKeys.forEach((key) => {
|
|
7018
7996
|
delete routerFM[key];
|
|
7019
7997
|
});
|
|
7020
|
-
|
|
7998
|
+
const manualExcerpt = typeof mdFm.excerpt === "string" ? stripEncryptedContent(mdFm.excerpt) : mdFm.excerpt;
|
|
7999
|
+
let resolvedExcerpt = manualExcerpt || (publicExcerpt ? await getExcerptByType(publicExcerpt, mdFm.excerpt_type || defaultFrontmatter.excerpt_type || valaxyConfig.siteConfig.excerpt.type, mdIt) : "");
|
|
8000
|
+
const explicitDescription = mdFm.description;
|
|
8001
|
+
const hasExplicitDescription = typeof explicitDescription === "string" ? explicitDescription.trim().length > 0 : explicitDescription != null && typeof explicitDescription === "object";
|
|
8002
|
+
const seoSource = encrypted ? "" : typeof mdFm.excerpt === "string" && mdFm.excerpt.trim() ? mdFm.excerpt : publicExcerpt || publicContent;
|
|
8003
|
+
const seoDescription = hasExplicitDescription ? "" : plainSeoDescription(seoSource, valaxyConfig.siteConfig.excerpt?.length || 200);
|
|
7021
8004
|
if (!resolvedExcerpt && valaxyConfig.siteConfig.excerpt.auto) {
|
|
7022
8005
|
const autoExcerptLength = valaxyConfig.siteConfig.excerpt.length;
|
|
7023
8006
|
const excerptType = mdFm.excerpt_type || defaultFrontmatter.excerpt_type || valaxyConfig.siteConfig.excerpt.type;
|
|
7024
|
-
const autoExcerptMd = generateAutoExcerptMd(
|
|
8007
|
+
const autoExcerptMd = generateAutoExcerptMd(publicContent, autoExcerptLength);
|
|
7025
8008
|
resolvedExcerpt = await getExcerptByType(autoExcerptMd, excerptType, mdIt);
|
|
7026
8009
|
}
|
|
7027
8010
|
route.addToMeta({
|
|
7028
8011
|
frontmatter: routerFM,
|
|
7029
|
-
excerpt: resolvedExcerpt
|
|
8012
|
+
excerpt: resolvedExcerpt,
|
|
8013
|
+
...seoDescription ? { seoDescription } : {}
|
|
7030
8014
|
});
|
|
7031
8015
|
if (data.layout) {
|
|
7032
8016
|
route.addToMeta({
|
|
@@ -7066,6 +8050,23 @@ async function createRouterOptions(valaxyApp, base, parseMatter = (source) => ma
|
|
|
7066
8050
|
async beforeWriteFiles(root) {
|
|
7067
8051
|
await valaxyApp.hooks.callHook("vue-router:beforeWriteFiles", root);
|
|
7068
8052
|
await valaxyConfig.router?.beforeWriteFiles?.(root);
|
|
8053
|
+
if (options.mode === "build" && !valaxyConfig.siteConfig.publishing?.drafts) {
|
|
8054
|
+
const prune = (parent) => {
|
|
8055
|
+
for (const route of parent.children) {
|
|
8056
|
+
prune(route);
|
|
8057
|
+
if (!route.meta.frontmatter?.draft)
|
|
8058
|
+
continue;
|
|
8059
|
+
if (route.children.length) {
|
|
8060
|
+
route.components.clear();
|
|
8061
|
+
route.meta = {};
|
|
8062
|
+
route.name = false;
|
|
8063
|
+
} else {
|
|
8064
|
+
route.delete();
|
|
8065
|
+
}
|
|
8066
|
+
}
|
|
8067
|
+
};
|
|
8068
|
+
prune(root);
|
|
8069
|
+
}
|
|
7069
8070
|
}
|
|
7070
8071
|
};
|
|
7071
8072
|
}
|
|
@@ -7397,6 +8398,8 @@ function renderPreloadLinks(modules, manifest) {
|
|
|
7397
8398
|
} else if (file.endsWith(".css")) {
|
|
7398
8399
|
links.push(`<link rel="stylesheet" href="${file}">`);
|
|
7399
8400
|
} else if (file.endsWith(".woff") || file.endsWith(".woff2")) {
|
|
8401
|
+
if (/(?:^|\/)KaTeX_[^/]+$/.test(file))
|
|
8402
|
+
continue;
|
|
7400
8403
|
links.push(`<link rel="preload" href="${file}" as="font" type="font/${file.endsWith(".woff2") ? "woff2" : "woff"}" crossorigin>`);
|
|
7401
8404
|
} else if (file.endsWith(".gif") || file.endsWith(".jpg") || file.endsWith(".jpeg") || file.endsWith(".png") || file.endsWith(".webp") || file.endsWith(".svg") || file.endsWith(".avif")) {
|
|
7402
8405
|
links.push(`<link rel="preload" href="${file}" as="image">`);
|
|
@@ -7427,6 +8430,36 @@ function routeToFileName(route) {
|
|
|
7427
8430
|
return route.slice(1);
|
|
7428
8431
|
return `${route}.html`.slice(1);
|
|
7429
8432
|
}
|
|
8433
|
+
function trailingSlashAlias(route) {
|
|
8434
|
+
if (!route || route === "/" || route.endsWith("/"))
|
|
8435
|
+
return;
|
|
8436
|
+
const file = routeToFileName(route);
|
|
8437
|
+
if (!file.endsWith(".html") || file.endsWith("/index.html"))
|
|
8438
|
+
return;
|
|
8439
|
+
return `${file.slice(0, -".html".length)}/index.html`;
|
|
8440
|
+
}
|
|
8441
|
+
async function fileExists(file) {
|
|
8442
|
+
try {
|
|
8443
|
+
await access(file, constants.F_OK);
|
|
8444
|
+
return true;
|
|
8445
|
+
} catch {
|
|
8446
|
+
return false;
|
|
8447
|
+
}
|
|
8448
|
+
}
|
|
8449
|
+
async function writeTrailingSlashAliases(outDir, routes) {
|
|
8450
|
+
const outputs = new Set(routes.map(routeToFileName));
|
|
8451
|
+
await Promise.all(routes.map(async (route) => {
|
|
8452
|
+
const alias = trailingSlashAlias(route);
|
|
8453
|
+
if (!alias || outputs.has(alias))
|
|
8454
|
+
return;
|
|
8455
|
+
const from = resolve(outDir, routeToFileName(route));
|
|
8456
|
+
const to = resolve(outDir, alias);
|
|
8457
|
+
if (!await fileExists(from) || await fileExists(to))
|
|
8458
|
+
return;
|
|
8459
|
+
await mkdir(dirname(to), { recursive: true });
|
|
8460
|
+
await copyFile(from, to);
|
|
8461
|
+
}));
|
|
8462
|
+
}
|
|
7430
8463
|
|
|
7431
8464
|
function tryGC() {
|
|
7432
8465
|
if (typeof globalThis.gc === "function")
|
|
@@ -7462,6 +8495,7 @@ async function ssgBuild(valaxyApp, viteConfig = {}, userSsgOptions = {}) {
|
|
|
7462
8495
|
const configOutDir = viteConfig.build?.outDir || "dist";
|
|
7463
8496
|
const outDir = isAbsolute$1(configOutDir) ? configOutDir : resolve(options.userRoot, configOutDir);
|
|
7464
8497
|
const ssgTemp = resolve(outDir, ".vite-ssg-temp");
|
|
8498
|
+
let routePaths = [];
|
|
7465
8499
|
const defaultConfig = {
|
|
7466
8500
|
...defaultViteConfig,
|
|
7467
8501
|
plugins: await profileBuildPhase("plugins", () => ViteValaxyPlugins(valaxyApp, {}, viteConfig, 2)),
|
|
@@ -7504,7 +8538,6 @@ async function ssgBuild(valaxyApp, viteConfig = {}, userSsgOptions = {}) {
|
|
|
7504
8538
|
tryGC();
|
|
7505
8539
|
const entryPath = resolve(ssgTemp, "entry-ssr.mjs");
|
|
7506
8540
|
const { render, routes } = await profileBuildPhase("server-load", () => import(pathToFileURL(entryPath).href));
|
|
7507
|
-
let routePaths;
|
|
7508
8541
|
if (userSsgOptions.includedRoutes) {
|
|
7509
8542
|
routePaths = await userSsgOptions.includedRoutes(routesToPaths(routes), routes);
|
|
7510
8543
|
} else if (userSsgOptions.includeAllRoutes) {
|
|
@@ -7546,8 +8579,11 @@ async function ssgBuild(valaxyApp, viteConfig = {}, userSsgOptions = {}) {
|
|
|
7546
8579
|
});
|
|
7547
8580
|
}
|
|
7548
8581
|
generateSitemap({
|
|
7549
|
-
hostname: options.config.siteConfig.url
|
|
8582
|
+
hostname: options.config.siteConfig.url,
|
|
8583
|
+
outDir,
|
|
8584
|
+
exclude: notFoundSitemapPaths(routePaths)
|
|
7550
8585
|
});
|
|
8586
|
+
await writeTrailingSlashAliases(outDir, routePaths);
|
|
7551
8587
|
if (userSsgOptions.onFinished)
|
|
7552
8588
|
await userSsgOptions.onFinished();
|
|
7553
8589
|
}
|
|
@@ -8052,7 +9088,7 @@ async function execBuild({ ssg, root, output, log, siteUrl }) {
|
|
|
8052
9088
|
if (!await isPagesDirExist(root))
|
|
8053
9089
|
throw new Error(`Pages directory not found: ${root}`);
|
|
8054
9090
|
const userRoot = path.resolve(root);
|
|
8055
|
-
const options = await profileBuildPhase("resolve-options", () => resolveOptions$
|
|
9091
|
+
const options = await profileBuildPhase("resolve-options", () => resolveOptions$2({ userRoot }, "build"));
|
|
8056
9092
|
if (siteUrl)
|
|
8057
9093
|
options.config.siteConfig.url = siteUrl;
|
|
8058
9094
|
setTimezone(options.config.siteConfig.timezone);
|
|
@@ -8216,8 +9252,12 @@ function createContentService(app, settings = {}) {
|
|
|
8216
9252
|
let release;
|
|
8217
9253
|
let disposed = false;
|
|
8218
9254
|
const parser = createMarkdownEngine();
|
|
8219
|
-
function
|
|
8220
|
-
|
|
9255
|
+
function unpublished(pagePath) {
|
|
9256
|
+
return isUnpublishedPage(pagePath.replace(/^pages\//, ""), config.siteConfig.publishing);
|
|
9257
|
+
}
|
|
9258
|
+
function visible(pagePath, data) {
|
|
9259
|
+
const keptPrivate = unpublished(pagePath) || Boolean(data.draft);
|
|
9260
|
+
if (settings.publicOnly && (data.password || data.encrypt || data.gallery_password || data.hide || keptPrivate && !settings.includeDrafts))
|
|
8221
9261
|
throw new Error("Page unavailable under the MCP visibility policy.");
|
|
8222
9262
|
}
|
|
8223
9263
|
async function read(path) {
|
|
@@ -8244,7 +9284,7 @@ function createContentService(app, settings = {}) {
|
|
|
8244
9284
|
const options = await routerOptions;
|
|
8245
9285
|
const routes = [];
|
|
8246
9286
|
routerApp.options.redirects.length = 0;
|
|
8247
|
-
const context = createRoutesContext(resolveOptions$
|
|
9287
|
+
const context = createRoutesContext(resolveOptions$3({
|
|
8248
9288
|
...options,
|
|
8249
9289
|
root: userRoot,
|
|
8250
9290
|
dts: false,
|
|
@@ -8272,7 +9312,7 @@ function createContentService(app, settings = {}) {
|
|
|
8272
9312
|
function project(path, file, routes, data) {
|
|
8273
9313
|
const matches = routes.filter((route) => route.files.includes(file));
|
|
8274
9314
|
for (const route of matches)
|
|
8275
|
-
visible(route.frontmatter);
|
|
9315
|
+
visible(path, route.frontmatter);
|
|
8276
9316
|
const resolved = matches[0]?.frontmatter || data;
|
|
8277
9317
|
const draft = Boolean(resolved.draft);
|
|
8278
9318
|
const base = settings.base ?? config.vite?.base ?? "/";
|
|
@@ -8304,7 +9344,7 @@ function createContentService(app, settings = {}) {
|
|
|
8304
9344
|
const { raw, file } = await read(path);
|
|
8305
9345
|
const { data } = parseMatter(raw);
|
|
8306
9346
|
const merged = { ...config.siteConfig.frontmatter, ...data };
|
|
8307
|
-
visible(merged);
|
|
9347
|
+
visible(path, merged);
|
|
8308
9348
|
const routes = await scanRoutes();
|
|
8309
9349
|
return project(path, file, routes, merged);
|
|
8310
9350
|
});
|
|
@@ -8323,7 +9363,7 @@ function createContentService(app, settings = {}) {
|
|
|
8323
9363
|
return result();
|
|
8324
9364
|
}
|
|
8325
9365
|
const { data, content } = parsed;
|
|
8326
|
-
visible({ ...config.siteConfig.frontmatter, ...data });
|
|
9366
|
+
visible(path, { ...config.siteConfig.frontmatter, ...data });
|
|
8327
9367
|
const fieldLine = (key) => raw.split("\n").findIndex((line) => line.startsWith(`${key}:`)) + 1 || 1;
|
|
8328
9368
|
for (const key of ["title", "description", "layout"]) {
|
|
8329
9369
|
if (data[key] !== void 0 && typeof data[key] !== "string" && !(key === "layout" && data[key] === false))
|
|
@@ -8352,7 +9392,7 @@ function createContentService(app, settings = {}) {
|
|
|
8352
9392
|
return result();
|
|
8353
9393
|
}
|
|
8354
9394
|
const page = project(path, file, routes, data);
|
|
8355
|
-
if (!page.routes.length)
|
|
9395
|
+
if (!page.routes.length && !unpublished(path))
|
|
8356
9396
|
add("route-missing", "error", "This file does not appear in the resolved route tree.", "Check router exclusions, page overrides and route hooks.");
|
|
8357
9397
|
const routePaths = /* @__PURE__ */ new Map();
|
|
8358
9398
|
for (const route of routes) {
|
|
@@ -8469,7 +9509,7 @@ function registerContentCommands(cli) {
|
|
|
8469
9509
|
setEnv();
|
|
8470
9510
|
if (json)
|
|
8471
9511
|
setLogLevel(-999);
|
|
8472
|
-
const options = await resolveOptions$
|
|
9512
|
+
const options = await resolveOptions$2({ userRoot: resolve$1(root) });
|
|
8473
9513
|
setTimezone(options.config.siteConfig.timezone);
|
|
8474
9514
|
const app = createValaxyNode(options);
|
|
8475
9515
|
if (options.config.loaders?.length) {
|
|
@@ -8527,7 +9567,7 @@ async function collectDebugInfo() {
|
|
|
8527
9567
|
valaxy: version
|
|
8528
9568
|
};
|
|
8529
9569
|
try {
|
|
8530
|
-
const options = await resolveOptions$
|
|
9570
|
+
const options = await resolveOptions$2({ userRoot: process.cwd() });
|
|
8531
9571
|
info.userRoot = options.userRoot;
|
|
8532
9572
|
info.theme = options.theme;
|
|
8533
9573
|
info.themeVersion = options.config.themeConfig?.pkg?.version;
|
|
@@ -8640,7 +9680,7 @@ function registerDeployCommand(cli) {
|
|
|
8640
9680
|
if (shouldBuild) {
|
|
8641
9681
|
await execBuild({ ssg: true, root, output, log: "info" });
|
|
8642
9682
|
}
|
|
8643
|
-
const options = await resolveOptions$
|
|
9683
|
+
const options = await resolveOptions$2({ userRoot: root }, "build");
|
|
8644
9684
|
const configDeployType = type ?? options.config.deploy?.type;
|
|
8645
9685
|
const deployType = configDeployType ?? await select({
|
|
8646
9686
|
message: "Where do you want to deploy?",
|
|
@@ -8801,7 +9841,7 @@ async function startValaxyDev({
|
|
|
8801
9841
|
process.exit(0);
|
|
8802
9842
|
port = port || await findFreePort(4859);
|
|
8803
9843
|
const resolveTimer = countPerformanceTime();
|
|
8804
|
-
const resolvedOptions = await resolveOptions$
|
|
9844
|
+
const resolvedOptions = await resolveOptions$2({ userRoot: root });
|
|
8805
9845
|
vLogger.debug(`resolveOptions: ${resolveTimer()}`);
|
|
8806
9846
|
setTimezone(resolvedOptions.config.siteConfig.timezone);
|
|
8807
9847
|
const createNodeTimer = countPerformanceTime();
|
|
@@ -8920,7 +9960,7 @@ date: <%=date%>
|
|
|
8920
9960
|
`;
|
|
8921
9961
|
|
|
8922
9962
|
async function getTemplate(layout) {
|
|
8923
|
-
const { clientRoot, themeRoot } = await resolveOptions$
|
|
9963
|
+
const { clientRoot, themeRoot } = await resolveOptions$2({ userRoot });
|
|
8924
9964
|
const roots = [userRoot, themeRoot, clientRoot];
|
|
8925
9965
|
for (const root of roots) {
|
|
8926
9966
|
const scaffoldPath = path.resolve(root, "scaffolds", `${layout}.md`);
|
|
@@ -9040,4 +10080,4 @@ async function run(argv = hideBin(process.argv), options = {}) {
|
|
|
9040
10080
|
await cli.parseAsync();
|
|
9041
10081
|
}
|
|
9042
10082
|
|
|
9043
|
-
export {
|
|
10083
|
+
export { resolveValaxyConfig as $, ALL_ROUTE as A, isInstalledGlobally as B, isKatexEnabled as C, isKatexPluginNeeded as D, EXCERPT_SEPARATOR as E, isMathJaxEnabled as F, GLOBAL_STATE as G, isPath as H, loadAllContent as I, loadConfigFromFile as J, mergeValaxyConfig as K, mergeViteConfigs as L, postProcessForSSG as M, processValaxyOptions as N, registerDevCommand as O, PATHNAME_PROTOCOL_RE as P, resolveAddonsConfig as Q, resolveImportPath as R, StateManager as S, resolveImportUrl as T, resolveOptions$2 as U, ViteValaxyPlugins as V, resolveSiteConfig as W, resolveSiteConfigFromRoot as X, resolveThemeConfigFromRoot as Y, resolveThemeValaxyConfig as Z, resolveUserThemeConfig as _, createContentService as a, resolveValaxyConfigFromRoot as a0, run as a1, ssgBuild as a2, startValaxyDev as a3, toAtFS as a4, transformObject as a5, version as a6, build as b, createCli as c, createMemoryReleasePlugin as d, createServer as e, createValaxyNode as f, createValaxyPlugin as g, customElements as h, defaultSiteConfig as i, defaultValaxyConfig as j, defaultViteConfig as k, defineAddon as l, defineConfig as m, defineSiteConfig as n, defineTheme as o, defineValaxyAddon as p, defineValaxyConfig as q, defineValaxyTheme as r, desktopRuntimeVersion as s, encryptContent as t, execBuild as u, generateClientRedirects as v, getGitTimestamp as w, getIndexHtml as x, getServerInfoText as y, isExternal as z };
|