valaxy 1.3.2 → 1.3.4
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/client/components/AppLink.vue +2 -2
- package/client/components/ValaxyDecrypt.vue +5 -3
- package/client/components/ValaxyMd.vue +2 -3
- package/client/composables/app/useValaxyApp.ts +1 -0
- package/client/composables/app/useValaxyHead.ts +11 -3
- package/client/composables/features/copy-code.ts +64 -38
- package/client/composables/features/copy-markdown.ts +2 -6
- package/client/composables/search/useFuseSearch.ts +38 -4
- package/client/composables/search/useLocalSearch.ts +47 -13
- package/client/config.ts +1 -0
- package/client/utils/router.ts +83 -37
- package/dist/node/cli/index.d.mts +1 -1
- package/dist/node/cli/index.mjs +6 -5
- package/dist/node/index.d.mts +22 -6
- package/dist/node/index.mjs +6 -5
- package/dist/shared/{valaxy.BIKfV_jq.mjs → valaxy.DQnMfBEN.mjs} +1026 -340
- package/package.json +4 -4
- package/shared/page-policy.ts +3 -9
- package/shared/utils/index.ts +2 -0
- package/shared/utils/sanitize.ts +82 -0
- package/shared/utils/uri.ts +93 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import path, { resolve, basename, dirname, relative as relative$1,
|
|
1
|
+
import path, { resolve, basename, dirname, join, relative as relative$1, sep as sep$1, isAbsolute as isAbsolute$1, parse } from 'node:path';
|
|
2
2
|
import process from 'node:process';
|
|
3
3
|
import yargs from 'yargs';
|
|
4
4
|
import { hideBin } from 'yargs/helpers';
|
|
@@ -12,7 +12,7 @@ import * as yaml from 'js-yaml';
|
|
|
12
12
|
import { dump, load, CORE_SCHEMA } from 'js-yaml';
|
|
13
13
|
import { isFunction, ensurePrefix, slash as slash$1, uniq as uniq$1, ensureSuffix, isObject } from '@antfu/utils';
|
|
14
14
|
import _debug from 'debug';
|
|
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';
|
|
15
|
+
import path$1, { resolve as resolve$1, relative, isAbsolute, sep, normalize, join as join$1, basename as basename$1, dirname as dirname$1 } from 'pathe';
|
|
16
16
|
import defu, { createDefu } from 'defu';
|
|
17
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';
|
|
@@ -23,13 +23,16 @@ import spawn$1, { spawn } from 'cross-spawn';
|
|
|
23
23
|
import { resolvePath } from 'mlly';
|
|
24
24
|
import { resolveGlobal } from 'resolve-global';
|
|
25
25
|
import { normalizeRepositoryUrl } from '@valaxyjs/utils';
|
|
26
|
-
import { existsSync, readFileSync,
|
|
26
|
+
import { realpathSync, existsSync, readFileSync, statSync } from 'node:fs';
|
|
27
|
+
import pMap from 'p-map';
|
|
27
28
|
import picomatch from 'picomatch';
|
|
28
29
|
import { readFile, mkdir, writeFile, realpath, copyFile, access, constants, rm, stat } from 'node:fs/promises';
|
|
29
30
|
import dayjs from 'dayjs';
|
|
30
31
|
import { Feed } from 'feed';
|
|
31
32
|
import { createMarkdownExit } from 'markdown-exit';
|
|
32
33
|
import { table, getBorderCharacters } from 'table';
|
|
34
|
+
import { Parser } from 'htmlparser2';
|
|
35
|
+
import MagicString from 'magic-string';
|
|
33
36
|
import { createHooks } from 'hookable';
|
|
34
37
|
import { Unhead } from '@unhead/bundler/vite';
|
|
35
38
|
import { groupIconMdPlugin, groupIconVitePlugin } from 'vitepress-plugin-group-icons';
|
|
@@ -38,8 +41,6 @@ import chokidar from 'chokidar';
|
|
|
38
41
|
import { createUnplugin, createVitePlugin } from 'unplugin';
|
|
39
42
|
import { createFilter } from 'unplugin-utils';
|
|
40
43
|
import { createDebug } from 'obug';
|
|
41
|
-
import MagicString from 'magic-string';
|
|
42
|
-
import pMap from 'p-map';
|
|
43
44
|
import pascalCase$1 from 'pascalcase';
|
|
44
45
|
import VueI18n from '@intlify/unplugin-vue-i18n/vite';
|
|
45
46
|
import MiniSearch from 'minisearch';
|
|
@@ -53,7 +54,6 @@ import { full } from 'markdown-it-emoji';
|
|
|
53
54
|
import footnotePlugin from 'markdown-it-footnote';
|
|
54
55
|
import imageFigures from 'markdown-it-image-figures';
|
|
55
56
|
import TaskLists from 'markdown-it-task-lists';
|
|
56
|
-
import { URL as URL$1, pathToFileURL } from 'node:url';
|
|
57
57
|
import container from 'markdown-it-container';
|
|
58
58
|
import katex from 'katex';
|
|
59
59
|
import 'katex/contrib/mhchem';
|
|
@@ -62,8 +62,9 @@ import { createJiti } from 'jiti';
|
|
|
62
62
|
import { transformerDirectives, transformerVariantGroup, presetWind4, presetAttributify, presetIcons, presetTypography } from 'unocss';
|
|
63
63
|
import { convert } from 'html-to-text';
|
|
64
64
|
import VueRouter from 'vue-router/vite';
|
|
65
|
-
import
|
|
65
|
+
import { pathToFileURL } from 'node:url';
|
|
66
66
|
import { renderSSRHead } from '@unhead/vue/server';
|
|
67
|
+
import escapeHtml$1 from 'escape-html';
|
|
67
68
|
import { createRoutesContext, resolveOptions as resolveOptions$3 } from 'vue-router/unplugin';
|
|
68
69
|
import { execSync, exec } from 'node:child_process';
|
|
69
70
|
import { intro, confirm, isCancel, cancel, select, outro } from '@clack/prompts';
|
|
@@ -72,7 +73,7 @@ import * as readline from 'node:readline';
|
|
|
72
73
|
import qrcode from 'qrcode';
|
|
73
74
|
import ejs from 'ejs';
|
|
74
75
|
|
|
75
|
-
const version = "1.3.
|
|
76
|
+
const version = "1.3.4";
|
|
76
77
|
|
|
77
78
|
const GLOBAL_STATE = {
|
|
78
79
|
valaxyApp: void 0,
|
|
@@ -238,14 +239,8 @@ function mergePageExcludes(publishing, userExclude) {
|
|
|
238
239
|
return userExclude(defaults);
|
|
239
240
|
return [...defaults, ...normalizeExcludeGlobs(userExclude)];
|
|
240
241
|
}
|
|
241
|
-
function
|
|
242
|
-
|
|
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];
|
|
242
|
+
function isNotFoundPagePath(path) {
|
|
243
|
+
return /\/404(?:\.html|\/(?:index\.html)?)?$/.test(path);
|
|
249
244
|
}
|
|
250
245
|
|
|
251
246
|
function publicAuthor(author) {
|
|
@@ -351,6 +346,110 @@ function extractMarkdownImage(code) {
|
|
|
351
346
|
});
|
|
352
347
|
}
|
|
353
348
|
|
|
349
|
+
const HTML_ESCAPE_MAP = {
|
|
350
|
+
"&": "&",
|
|
351
|
+
"<": "<",
|
|
352
|
+
">": ">",
|
|
353
|
+
'"': """,
|
|
354
|
+
"'": "'"
|
|
355
|
+
};
|
|
356
|
+
const SAFE_URL_PROTOCOLS = /* @__PURE__ */ new Set(["http:", "https:", "mailto:", "tel:"]);
|
|
357
|
+
const SAFE_DATA_IMAGE_RE = /^data:image\/(?:png|jpe?g|gif|webp|avif|x-icon|vnd\.microsoft\.icon|svg\+xml)[;,]/i;
|
|
358
|
+
function stripControlsAndSpaces(value) {
|
|
359
|
+
let out = "";
|
|
360
|
+
for (let i = 0; i < value.length; i++) {
|
|
361
|
+
const code = value.charCodeAt(i);
|
|
362
|
+
if (code > 32 && code !== 127)
|
|
363
|
+
out += value[i];
|
|
364
|
+
}
|
|
365
|
+
return out;
|
|
366
|
+
}
|
|
367
|
+
function hasControlChars(value) {
|
|
368
|
+
for (let i = 0; i < value.length; i++) {
|
|
369
|
+
const code = value.charCodeAt(i);
|
|
370
|
+
if (code <= 31 || code === 127)
|
|
371
|
+
return true;
|
|
372
|
+
}
|
|
373
|
+
return false;
|
|
374
|
+
}
|
|
375
|
+
function escapeHtml(str = "") {
|
|
376
|
+
return str.replace(/[&<>"']/g, (ch) => HTML_ESCAPE_MAP[ch]);
|
|
377
|
+
}
|
|
378
|
+
function serializeInlineJsString(value) {
|
|
379
|
+
return JSON.stringify(value).replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026").replace(/'/g, "\\u0027").replace(/\//g, "\\u002f").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
380
|
+
}
|
|
381
|
+
function sanitizeUrl(url, fallback = "#", options = {}) {
|
|
382
|
+
if (!url)
|
|
383
|
+
return fallback;
|
|
384
|
+
const trimmed = url.trim();
|
|
385
|
+
if (!trimmed || hasControlChars(trimmed))
|
|
386
|
+
return fallback;
|
|
387
|
+
const normalized = stripControlsAndSpaces(trimmed);
|
|
388
|
+
if (!normalized)
|
|
389
|
+
return fallback;
|
|
390
|
+
if (options.allowDataImage && SAFE_DATA_IMAGE_RE.test(normalized))
|
|
391
|
+
return trimmed;
|
|
392
|
+
const schemeMatch = normalized.match(/^([a-z][a-z\d+.-]*):/i);
|
|
393
|
+
if (schemeMatch && !SAFE_URL_PROTOCOLS.has(`${schemeMatch[1].toLowerCase()}:`))
|
|
394
|
+
return fallback;
|
|
395
|
+
return trimmed;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
const PROTOCOL_PREFIX_RE = /^(?:[a-z][a-z\d+.-]*:)?\/\//i;
|
|
399
|
+
function safeDecodeURI(uri) {
|
|
400
|
+
try {
|
|
401
|
+
return decodeURI(uri);
|
|
402
|
+
} catch {
|
|
403
|
+
return uri;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
function safeDecodeURIComponent(uri) {
|
|
407
|
+
try {
|
|
408
|
+
return decodeURIComponent(uri);
|
|
409
|
+
} catch {
|
|
410
|
+
return uri;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
function safeParseUrl(url, base) {
|
|
414
|
+
try {
|
|
415
|
+
return new URL(url, base);
|
|
416
|
+
} catch {
|
|
417
|
+
return null;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
function joinBaseUrl(base = "/", routePath = "") {
|
|
421
|
+
const normalizedBase = (base || "/").replace(/\\/g, "/");
|
|
422
|
+
const normalizedRoute = routePath.replace(/\\/g, "/").replace(/^\/+/, "");
|
|
423
|
+
const protocolMatch = normalizedBase.match(PROTOCOL_PREFIX_RE);
|
|
424
|
+
if (protocolMatch) {
|
|
425
|
+
const prefix = protocolMatch[0];
|
|
426
|
+
const afterProtocol = normalizedBase.slice(prefix.length);
|
|
427
|
+
const slashIdx = afterProtocol.indexOf("/");
|
|
428
|
+
const authority = slashIdx === -1 ? afterProtocol : afterProtocol.slice(0, slashIdx);
|
|
429
|
+
const basePath = slashIdx === -1 ? "" : afterProtocol.slice(slashIdx).replace(/\/+$/, "");
|
|
430
|
+
const joinedPath = normalizedRoute ? `${basePath}/${normalizedRoute}` : `${basePath || ""}/`;
|
|
431
|
+
return `${prefix}${authority}${joinedPath.startsWith("/") ? joinedPath : `/${joinedPath}`}`;
|
|
432
|
+
}
|
|
433
|
+
if (normalizedBase.startsWith("./") || normalizedBase === ".") {
|
|
434
|
+
const cleanBase = normalizedBase.replace(/\/+$/, "");
|
|
435
|
+
const prefix = cleanBase === "." ? "./" : `${cleanBase}/`;
|
|
436
|
+
return `${prefix}${normalizedRoute}`;
|
|
437
|
+
}
|
|
438
|
+
const cleanBasePath = `/${normalizedBase.replace(/^\/+|\/+$/g, "")}`;
|
|
439
|
+
if (!normalizedRoute)
|
|
440
|
+
return cleanBasePath === "/" ? "/" : `${cleanBasePath}/`;
|
|
441
|
+
return cleanBasePath === "/" ? `/${normalizedRoute}` : `${cleanBasePath}/${normalizedRoute}`;
|
|
442
|
+
}
|
|
443
|
+
const INDEX_ONLY_SEGMENTS_RE = /^index(?:\/index)*$/;
|
|
444
|
+
function urlPathToMarkdownPath(urlPath) {
|
|
445
|
+
const normalized = urlPath.replace(/\\/g, "/").replace(/^\/+|\/+$/g, "");
|
|
446
|
+
const relativeFile = !normalized ? "index.md" : INDEX_ONLY_SEGMENTS_RE.test(normalized) ? `${normalized}/index.md` : `${normalized}.md`;
|
|
447
|
+
return {
|
|
448
|
+
href: `/${relativeFile}`,
|
|
449
|
+
relativeFile
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
|
|
354
453
|
function commonOptions(args) {
|
|
355
454
|
return args.positional("root", {
|
|
356
455
|
default: ".",
|
|
@@ -859,9 +958,35 @@ async function encryptContent(content, options) {
|
|
|
859
958
|
return Buffer$1.from(ciphertextData).toString("base64");
|
|
860
959
|
}
|
|
861
960
|
|
|
862
|
-
|
|
961
|
+
const pipelineCaches = /* @__PURE__ */ new WeakMap();
|
|
962
|
+
function getGitTimestampCache(scope) {
|
|
963
|
+
let cache = pipelineCaches.get(scope);
|
|
964
|
+
if (!cache) {
|
|
965
|
+
cache = /* @__PURE__ */ new Map();
|
|
966
|
+
pipelineCaches.set(scope, cache);
|
|
967
|
+
}
|
|
968
|
+
return cache;
|
|
969
|
+
}
|
|
970
|
+
function clearGitTimestampCache(cache, file) {
|
|
971
|
+
if (!file) {
|
|
972
|
+
cache.clear();
|
|
973
|
+
return;
|
|
974
|
+
}
|
|
863
975
|
const filePath = resolve(file);
|
|
864
|
-
|
|
976
|
+
const prefixCreated = `created:${filePath}:`;
|
|
977
|
+
const prefixUpdated = `updated:${filePath}:`;
|
|
978
|
+
for (const key of cache.keys()) {
|
|
979
|
+
if (key.startsWith(prefixCreated) || key.startsWith(prefixUpdated))
|
|
980
|
+
cache.delete(key);
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
function getGitTimestamp(file, type = "updated", cache) {
|
|
984
|
+
const filePath = resolve(file);
|
|
985
|
+
const cacheKey = `${type}:${filePath}:${process.env.PATH ?? ""}`;
|
|
986
|
+
const cached = cache?.get(cacheKey);
|
|
987
|
+
if (cached)
|
|
988
|
+
return cached;
|
|
989
|
+
const pending = new Promise((resolve) => {
|
|
865
990
|
const params = ["--literal-pathspecs", "log", "--follow", "--no-show-signature", "--format=%ct"];
|
|
866
991
|
if (type === "updated")
|
|
867
992
|
params.push("-1");
|
|
@@ -883,6 +1008,8 @@ function getGitTimestamp(file, type = "updated") {
|
|
|
883
1008
|
resolve(0);
|
|
884
1009
|
});
|
|
885
1010
|
});
|
|
1011
|
+
cache?.set(cacheKey, pending);
|
|
1012
|
+
return pending;
|
|
886
1013
|
}
|
|
887
1014
|
|
|
888
1015
|
function isExternal(str) {
|
|
@@ -1027,17 +1154,20 @@ function collectRedirects(redirectRules) {
|
|
|
1027
1154
|
return redirects;
|
|
1028
1155
|
}
|
|
1029
1156
|
async function writeRedirectFiles(route, filePath) {
|
|
1157
|
+
const safeRoute = sanitizeUrl(route, "/");
|
|
1158
|
+
const escapedRoute = escapeHtml(safeRoute);
|
|
1159
|
+
const jsRoute = serializeInlineJsString(safeRoute);
|
|
1030
1160
|
await fs.ensureFile(filePath);
|
|
1031
1161
|
await fs.writeFile(filePath, `
|
|
1032
1162
|
<!DOCTYPE html>
|
|
1033
1163
|
<html lang="en">
|
|
1034
1164
|
<head>
|
|
1035
1165
|
<meta charset="UTF-8">
|
|
1036
|
-
<meta http-equiv="refresh" content="0; url=${
|
|
1037
|
-
<link rel="canonical" href="${
|
|
1166
|
+
<meta http-equiv="refresh" content="0; url=${escapedRoute}">
|
|
1167
|
+
<link rel="canonical" href="${escapedRoute}">
|
|
1038
1168
|
</head>
|
|
1039
1169
|
<script>
|
|
1040
|
-
window.location.href =
|
|
1170
|
+
window.location.href = ${jsRoute} + window.location.search + window.location.hash
|
|
1041
1171
|
<\/script>
|
|
1042
1172
|
</html>
|
|
1043
1173
|
`);
|
|
@@ -1208,6 +1338,236 @@ const matterOptions = {
|
|
|
1208
1338
|
}
|
|
1209
1339
|
};
|
|
1210
1340
|
|
|
1341
|
+
function foucGuardHtml(maxDuration) {
|
|
1342
|
+
return [
|
|
1343
|
+
`<style id="valaxy-fouc">body{margin:0;opacity:0!important}</style>`,
|
|
1344
|
+
`<noscript><style>body{opacity:1!important}</style></noscript>`,
|
|
1345
|
+
`<script>(${foucGuardScript.toString()})(${maxDuration})<\/script>`
|
|
1346
|
+
].join("");
|
|
1347
|
+
}
|
|
1348
|
+
function foucGuardScript(maxDuration) {
|
|
1349
|
+
var done = 0;
|
|
1350
|
+
var observer = new MutationObserver(check);
|
|
1351
|
+
var timer = maxDuration ? setTimeout(reveal, maxDuration) : void 0;
|
|
1352
|
+
function reveal() {
|
|
1353
|
+
if (done) return;
|
|
1354
|
+
done = 1;
|
|
1355
|
+
observer.disconnect();
|
|
1356
|
+
clearTimeout(timer);
|
|
1357
|
+
document.removeEventListener("load", check, true);
|
|
1358
|
+
removeEventListener("load", reveal);
|
|
1359
|
+
var s = document.getElementById("valaxy-fouc");
|
|
1360
|
+
if (s) s.remove();
|
|
1361
|
+
}
|
|
1362
|
+
function check() {
|
|
1363
|
+
if (!document.body) return;
|
|
1364
|
+
var links = document.head.querySelectorAll('link[rel~="stylesheet"]');
|
|
1365
|
+
for (var i = 0; i < links.length; i++) {
|
|
1366
|
+
var link = links[i];
|
|
1367
|
+
if (!link.disabled && !link.sheet) return;
|
|
1368
|
+
}
|
|
1369
|
+
reveal();
|
|
1370
|
+
}
|
|
1371
|
+
observer.observe(document.documentElement, { childList: true });
|
|
1372
|
+
observer.observe(document.head, {
|
|
1373
|
+
childList: true,
|
|
1374
|
+
subtree: true,
|
|
1375
|
+
attributes: true,
|
|
1376
|
+
attributeFilter: ["media", "rel", "disabled"]
|
|
1377
|
+
});
|
|
1378
|
+
document.addEventListener("load", check, true);
|
|
1379
|
+
addEventListener("load", reveal);
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1382
|
+
function normalizeConfigPath(file) {
|
|
1383
|
+
const abs = resolve(file);
|
|
1384
|
+
try {
|
|
1385
|
+
return realpathSync(abs);
|
|
1386
|
+
} catch {
|
|
1387
|
+
return abs;
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
const VITE_DEFAULT_CONFIG_FILES = [
|
|
1391
|
+
"vite.config.js",
|
|
1392
|
+
"vite.config.mjs",
|
|
1393
|
+
"vite.config.ts",
|
|
1394
|
+
"vite.config.cjs",
|
|
1395
|
+
"vite.config.mts",
|
|
1396
|
+
"vite.config.cts"
|
|
1397
|
+
];
|
|
1398
|
+
async function findRootViteConfig(root) {
|
|
1399
|
+
for (const filename of VITE_DEFAULT_CONFIG_FILES) {
|
|
1400
|
+
const candidate = join(root, filename);
|
|
1401
|
+
if (await fs.exists(candidate))
|
|
1402
|
+
return candidate;
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
async function mergeViteConfigs({ userRoot, themeRoot }, command, mode = command === "build" ? "production" : "development", extraFiles = [], isSsrBuild, configLoader, logLevel, customLogger) {
|
|
1406
|
+
const configEnv = {
|
|
1407
|
+
mode,
|
|
1408
|
+
command,
|
|
1409
|
+
...isSsrBuild !== void 0 ? { isSsrBuild } : {}
|
|
1410
|
+
};
|
|
1411
|
+
let resolvedConfig = {};
|
|
1412
|
+
const discoveredFiles = (await Promise.all(
|
|
1413
|
+
uniq$1([themeRoot, userRoot]).map((root) => findRootViteConfig(root))
|
|
1414
|
+
)).filter((file) => Boolean(file));
|
|
1415
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1416
|
+
const files = [...discoveredFiles, ...extraFiles].filter((file) => {
|
|
1417
|
+
const key = normalizeConfigPath(file);
|
|
1418
|
+
if (seen.has(key))
|
|
1419
|
+
return false;
|
|
1420
|
+
seen.add(key);
|
|
1421
|
+
return true;
|
|
1422
|
+
});
|
|
1423
|
+
const viteConfigs = await Promise.all(
|
|
1424
|
+
files.map((file) => loadConfigFromFile$1(configEnv, file, void 0, logLevel, customLogger, configLoader))
|
|
1425
|
+
);
|
|
1426
|
+
for (const viteConfig of viteConfigs) {
|
|
1427
|
+
if (!viteConfig?.config)
|
|
1428
|
+
continue;
|
|
1429
|
+
resolvedConfig = mergeConfig(resolvedConfig, viteConfig.config);
|
|
1430
|
+
}
|
|
1431
|
+
return resolvedConfig;
|
|
1432
|
+
}
|
|
1433
|
+
async function getIndexHtml({ clientRoot, themeRoot, userRoot, config }, rawHtml) {
|
|
1434
|
+
let main = rawHtml;
|
|
1435
|
+
let head = "";
|
|
1436
|
+
let body = "";
|
|
1437
|
+
if (config.siteConfig.favicon) {
|
|
1438
|
+
const safeFavicon = sanitizeUrl(config.siteConfig.favicon, "", { allowDataImage: true });
|
|
1439
|
+
if (safeFavicon)
|
|
1440
|
+
head += `<link rel="icon" href="${escapeHtml(safeFavicon)}">`;
|
|
1441
|
+
}
|
|
1442
|
+
const roots = [userRoot, themeRoot];
|
|
1443
|
+
if (config.siteConfig.mode === "auto") {
|
|
1444
|
+
head += `
|
|
1445
|
+
<script>
|
|
1446
|
+
;(function () {
|
|
1447
|
+
const prefersDark =
|
|
1448
|
+
window.matchMedia &&
|
|
1449
|
+
window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
1450
|
+
const setting = localStorage.getItem('vueuse-color-scheme') || 'auto'
|
|
1451
|
+
if (setting === 'dark' || (prefersDark && setting !== 'light'))
|
|
1452
|
+
document.documentElement.classList.toggle('dark', true)
|
|
1453
|
+
})()
|
|
1454
|
+
<\/script>
|
|
1455
|
+
`;
|
|
1456
|
+
head += `<style type="text/css">
|
|
1457
|
+
:root { color-scheme: light dark; --va-c-bg: #fff; }
|
|
1458
|
+
html.dark { --va-c-bg: #000; }
|
|
1459
|
+
html { background-color: var(--va-c-bg); }
|
|
1460
|
+
</style>`;
|
|
1461
|
+
}
|
|
1462
|
+
const foucGuard = config.build?.foucGuard ?? {};
|
|
1463
|
+
const foucEnabled = foucGuard.enabled ?? true;
|
|
1464
|
+
const foucMaxDuration = foucGuard.maxDuration ?? 5e3;
|
|
1465
|
+
if (foucEnabled)
|
|
1466
|
+
head += foucGuardHtml(foucMaxDuration);
|
|
1467
|
+
if (config.siteConfig.lang) {
|
|
1468
|
+
head += `
|
|
1469
|
+
<script>
|
|
1470
|
+
const locale = localStorage.getItem('valaxy-locale') || ${serializeInlineJsString(config.siteConfig.lang)};
|
|
1471
|
+
document.documentElement.setAttribute('lang', locale);
|
|
1472
|
+
<\/script>
|
|
1473
|
+
`;
|
|
1474
|
+
}
|
|
1475
|
+
for (const root of roots) {
|
|
1476
|
+
const path = join(root, "index.html");
|
|
1477
|
+
if (!fs.existsSync(path))
|
|
1478
|
+
continue;
|
|
1479
|
+
const indexHtml = await fs.readFile(path, "utf-8");
|
|
1480
|
+
head += `
|
|
1481
|
+
${(indexHtml.match(/<head>([\s\S]*?)<\/head>/i)?.[1] || "").trim()}`;
|
|
1482
|
+
body += `
|
|
1483
|
+
${(indexHtml.match(/<body>([\s\S]*?)<\/body>/i)?.[1] || "").trim()}`;
|
|
1484
|
+
}
|
|
1485
|
+
main = main.replace("__ENTRY__", () => toAtFS(join(clientRoot, "main.ts"))).replace("<!-- head -->", () => head).replace("<!-- body -->", () => body);
|
|
1486
|
+
return main;
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1489
|
+
const resolvedClientInputsWeakMap = /* @__PURE__ */ new WeakMap();
|
|
1490
|
+
function resolvePublicDir(userRoot, publicDir) {
|
|
1491
|
+
if (publicDir === false)
|
|
1492
|
+
return false;
|
|
1493
|
+
return resolve(userRoot, publicDir || "public");
|
|
1494
|
+
}
|
|
1495
|
+
function resolveBuildPaths(options, viteConfig, explicitOutDir) {
|
|
1496
|
+
const rawOutDir = explicitOutDir ?? viteConfig?.build?.outDir ?? options.outDir ?? options.config?.vite?.build?.outDir ?? "dist";
|
|
1497
|
+
const outDir = resolve(options.userRoot, rawOutDir);
|
|
1498
|
+
const rawPublicDir = viteConfig?.publicDir !== void 0 ? viteConfig.publicDir : options.publicDir !== void 0 ? options.publicDir : options.config?.vite?.publicDir;
|
|
1499
|
+
const publicDir = resolvePublicDir(options.userRoot, rawPublicDir);
|
|
1500
|
+
const base = viteConfig?.base ?? options.base ?? options.config?.vite?.base ?? "/";
|
|
1501
|
+
return { outDir, publicDir, base };
|
|
1502
|
+
}
|
|
1503
|
+
async function resolveEffectiveViteConfig(options, command, callerViteConfig = {}, explicitOutDir, isSsrBuild, persistPaths = isSsrBuild !== true) {
|
|
1504
|
+
const preloadedInput = resolvedClientInputsWeakMap.get(callerViteConfig);
|
|
1505
|
+
if (preloadedInput) {
|
|
1506
|
+
if (isSsrBuild !== true) {
|
|
1507
|
+
const paths2 = resolveBuildPaths(options, callerViteConfig, explicitOutDir ?? preloadedInput.explicitOutDir);
|
|
1508
|
+
if (persistPaths) {
|
|
1509
|
+
options.outDir = paths2.outDir;
|
|
1510
|
+
options.publicDir = paths2.publicDir;
|
|
1511
|
+
options.base = paths2.base;
|
|
1512
|
+
}
|
|
1513
|
+
return {
|
|
1514
|
+
viteConfig: callerViteConfig,
|
|
1515
|
+
...paths2
|
|
1516
|
+
};
|
|
1517
|
+
}
|
|
1518
|
+
callerViteConfig = preloadedInput.callerViteConfig;
|
|
1519
|
+
explicitOutDir = explicitOutDir ?? preloadedInput.explicitOutDir;
|
|
1520
|
+
}
|
|
1521
|
+
const mode = callerViteConfig.mode ?? options.config.vite?.mode ?? ("production" );
|
|
1522
|
+
if (!process.env.NODE_ENV)
|
|
1523
|
+
process.env.NODE_ENV = "production" ;
|
|
1524
|
+
const explicitConfigFile = callerViteConfig.configFile !== void 0 ? callerViteConfig.configFile : options.config.vite?.configFile;
|
|
1525
|
+
const configLoader = callerViteConfig.configLoader ?? options.config.vite?.configLoader;
|
|
1526
|
+
const logLevel = callerViteConfig.logLevel ?? options.config.vite?.logLevel;
|
|
1527
|
+
const customLogger = callerViteConfig.customLogger ?? options.config.vite?.customLogger;
|
|
1528
|
+
const resolvedExplicitConfigFile = typeof explicitConfigFile === "string" ? resolve(explicitConfigFile) : void 0;
|
|
1529
|
+
const baseViteConfig = explicitConfigFile === false ? {} : await mergeViteConfigs(
|
|
1530
|
+
options,
|
|
1531
|
+
command,
|
|
1532
|
+
mode,
|
|
1533
|
+
resolvedExplicitConfigFile ? [resolvedExplicitConfigFile] : [],
|
|
1534
|
+
isSsrBuild,
|
|
1535
|
+
configLoader,
|
|
1536
|
+
logLevel,
|
|
1537
|
+
customLogger
|
|
1538
|
+
);
|
|
1539
|
+
const merged = mergeConfig(
|
|
1540
|
+
mergeConfig(baseViteConfig, options.config.vite || {}),
|
|
1541
|
+
callerViteConfig
|
|
1542
|
+
);
|
|
1543
|
+
const paths = resolveBuildPaths(options, merged, explicitOutDir);
|
|
1544
|
+
if (persistPaths) {
|
|
1545
|
+
options.outDir = paths.outDir;
|
|
1546
|
+
options.publicDir = paths.publicDir;
|
|
1547
|
+
options.base = paths.base;
|
|
1548
|
+
}
|
|
1549
|
+
const viteConfig = mergeConfig(merged, {
|
|
1550
|
+
// Config files were already evaluated for this pass, so disable Vite's own loading
|
|
1551
|
+
// to prevent duplicate plugin registration and precedence inversion.
|
|
1552
|
+
configFile: false,
|
|
1553
|
+
base: paths.base,
|
|
1554
|
+
publicDir: paths.publicDir,
|
|
1555
|
+
build: {
|
|
1556
|
+
outDir: paths.outDir
|
|
1557
|
+
}
|
|
1558
|
+
});
|
|
1559
|
+
if (isSsrBuild !== true) {
|
|
1560
|
+
resolvedClientInputsWeakMap.set(viteConfig, {
|
|
1561
|
+
callerViteConfig,
|
|
1562
|
+
explicitOutDir
|
|
1563
|
+
});
|
|
1564
|
+
}
|
|
1565
|
+
return {
|
|
1566
|
+
viteConfig,
|
|
1567
|
+
...paths
|
|
1568
|
+
};
|
|
1569
|
+
}
|
|
1570
|
+
|
|
1211
1571
|
function isProd() {
|
|
1212
1572
|
return process.env.NODE_ENV === "production";
|
|
1213
1573
|
}
|
|
@@ -1259,8 +1619,12 @@ async function discoverPageFiles(userRoot, include = ["**/*.md"]) {
|
|
|
1259
1619
|
for (const root of getPageRoots(userRoot)) {
|
|
1260
1620
|
const files = await glob(include, { cwd: root, ignore: ["**/node_modules/**"], onlyFiles: true });
|
|
1261
1621
|
for (const page of files.sort()) {
|
|
1622
|
+
const resolved = resolve$1(root, page);
|
|
1623
|
+
const rel = relative(root, resolved);
|
|
1624
|
+
if (!rel || rel === ".." || rel.startsWith(`..${sep}`) || !getPagePath(resolved, userRoot))
|
|
1625
|
+
continue;
|
|
1262
1626
|
if (!pages.has(page))
|
|
1263
|
-
pages.set(page,
|
|
1627
|
+
pages.set(page, resolved);
|
|
1264
1628
|
}
|
|
1265
1629
|
}
|
|
1266
1630
|
return pages;
|
|
@@ -1286,8 +1650,8 @@ async function generateFuseList(options) {
|
|
|
1286
1650
|
loadLocalesYml(path.resolve(options.userRoot, "locales"));
|
|
1287
1651
|
const globalAuthor = nodeT(options.config.siteConfig.author.name, options.config.siteConfig.lang || "en");
|
|
1288
1652
|
const posts = [];
|
|
1289
|
-
for
|
|
1290
|
-
const raw = fs.
|
|
1653
|
+
for (const i of files) {
|
|
1654
|
+
const raw = await fs.readFile(i, "utf-8");
|
|
1291
1655
|
const { data, content: rawContent } = matter(raw, matterOptions);
|
|
1292
1656
|
const fmData = { ...options.config.siteConfig.frontmatter, ...data };
|
|
1293
1657
|
const content = stripEncryptedContent(rawContent);
|
|
@@ -1305,8 +1669,10 @@ async function generateFuseList(options) {
|
|
|
1305
1669
|
if (fmData.password || fmData.encrypt === true)
|
|
1306
1670
|
continue;
|
|
1307
1671
|
const extendKeys = options.config.fuse?.extendKeys || [];
|
|
1308
|
-
const
|
|
1309
|
-
const
|
|
1672
|
+
const { base } = resolveBuildPaths(options);
|
|
1673
|
+
const pagePath = (getPagePath(i, options.userRoot) || path.relative(path.resolve(options.userRoot, "pages"), i)).replace(/\\/g, "/");
|
|
1674
|
+
const cleanRoute = pagePath.replace(/(?:^|\/)index\.md$/, "").replace(/\.md$/, "");
|
|
1675
|
+
const link = joinBaseUrl(base, cleanRoute);
|
|
1310
1676
|
const fuseListItem = {
|
|
1311
1677
|
title: fmData.title || "",
|
|
1312
1678
|
tags: (typeof fmData.tags === "string" ? [fmData.tags] : fmData.tags) || [],
|
|
@@ -1329,34 +1695,38 @@ async function generateFuseList(options) {
|
|
|
1329
1695
|
}
|
|
1330
1696
|
return posts;
|
|
1331
1697
|
}
|
|
1332
|
-
async function execFuse(options) {
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
const
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
const gitignore = await fs.readFile(gitignorePath, "utf-8");
|
|
1350
|
-
const ignorePath = publicRelativeFile.replace(/\\/g, "/");
|
|
1351
|
-
if (!gitignore.includes(ignorePath)) {
|
|
1352
|
-
await fs.appendFile(gitignorePath, `
|
|
1698
|
+
async function execFuse(options, target = "both", precomputedList) {
|
|
1699
|
+
const fuseList = precomputedList ?? await (async () => {
|
|
1700
|
+
consola.info("Start generate fuse list...");
|
|
1701
|
+
return await generateFuseList(options);
|
|
1702
|
+
})();
|
|
1703
|
+
const { outDir, publicDir } = resolveBuildPaths(options);
|
|
1704
|
+
if ((target === "both" || target === "public") && publicDir !== false) {
|
|
1705
|
+
const publicFuseFile = path.resolve(publicDir, options.config.siteConfig.fuse.dataPath);
|
|
1706
|
+
await fs.ensureFile(publicFuseFile);
|
|
1707
|
+
await fs.writeJson(publicFuseFile, fuseList);
|
|
1708
|
+
consola.success(`Generate fuse list in ${colors.dim(publicDir)}`);
|
|
1709
|
+
try {
|
|
1710
|
+
const gitignorePath = path.resolve(options.userRoot, ".gitignore");
|
|
1711
|
+
const gitignore = await fs.readFile(gitignorePath, "utf-8");
|
|
1712
|
+
const ignorePath = path.relative(options.userRoot, publicFuseFile).replace(/\\/g, "/");
|
|
1713
|
+
if (ignorePath && !ignorePath.startsWith("..") && !path.isAbsolute(ignorePath) && !gitignore.includes(ignorePath)) {
|
|
1714
|
+
await fs.appendFile(gitignorePath, `
|
|
1353
1715
|
# valaxy fuse
|
|
1354
1716
|
${ignorePath}
|
|
1355
1717
|
`);
|
|
1356
|
-
|
|
1718
|
+
consola.success(`Add ${colors.dim(ignorePath)} to ${colors.dim(".gitignore")}`);
|
|
1719
|
+
}
|
|
1720
|
+
} catch {
|
|
1357
1721
|
}
|
|
1358
|
-
} catch {
|
|
1359
1722
|
}
|
|
1723
|
+
if (target === "both" || target === "dist") {
|
|
1724
|
+
const distFuseFile = path.resolve(outDir, options.config.siteConfig.fuse.dataPath);
|
|
1725
|
+
await fs.ensureFile(distFuseFile);
|
|
1726
|
+
await fs.writeJson(distFuseFile, fuseList);
|
|
1727
|
+
consola.success(`Generate fuse list in ${colors.dim(outDir)}`);
|
|
1728
|
+
}
|
|
1729
|
+
return fuseList;
|
|
1360
1730
|
}
|
|
1361
1731
|
function registerFuseCommand(cli) {
|
|
1362
1732
|
cli.command(
|
|
@@ -1366,6 +1736,7 @@ function registerFuseCommand(cli) {
|
|
|
1366
1736
|
async ({ root }) => {
|
|
1367
1737
|
setEnvProd();
|
|
1368
1738
|
const options = await resolveOptions$2({ userRoot: root }, "build");
|
|
1739
|
+
await resolveEffectiveViteConfig(options, "build");
|
|
1369
1740
|
await execFuse(options);
|
|
1370
1741
|
}
|
|
1371
1742
|
);
|
|
@@ -1375,8 +1746,13 @@ const fuseModule = defineValaxyModule({
|
|
|
1375
1746
|
registerFuseCommand(cli);
|
|
1376
1747
|
},
|
|
1377
1748
|
setup(node) {
|
|
1749
|
+
let cachedFuseList;
|
|
1378
1750
|
node.hook("build:before", async () => {
|
|
1379
|
-
await execFuse(node.options);
|
|
1751
|
+
cachedFuseList = await execFuse(node.options, "public");
|
|
1752
|
+
});
|
|
1753
|
+
node.hook("build:after", async () => {
|
|
1754
|
+
await execFuse(node.options, "dist", cachedFuseList);
|
|
1755
|
+
cachedFuseList = void 0;
|
|
1380
1756
|
});
|
|
1381
1757
|
}
|
|
1382
1758
|
});
|
|
@@ -1385,11 +1761,11 @@ async function scanPageFiles(userRoot, include) {
|
|
|
1385
1761
|
return [...(await discoverPageFiles(userRoot, include)).values()];
|
|
1386
1762
|
}
|
|
1387
1763
|
async function readPostFiles(files, defaults = {}) {
|
|
1388
|
-
return
|
|
1764
|
+
return pMap(files, async (filePath) => {
|
|
1389
1765
|
const raw = await readFile(filePath, "utf-8");
|
|
1390
1766
|
const { data, content, excerpt } = matter(raw, matterOptions);
|
|
1391
1767
|
return { data: { ...defaults, ...data }, content, excerpt, filePath };
|
|
1392
|
-
})
|
|
1768
|
+
}, { concurrency: 32 });
|
|
1393
1769
|
}
|
|
1394
1770
|
function filterPublicPosts(posts, publishing, userRoot) {
|
|
1395
1771
|
return posts.filter(({ data, filePath }) => {
|
|
@@ -1461,7 +1837,7 @@ async function build$2(options) {
|
|
|
1461
1837
|
const posts = await loadLlmsPosts(options);
|
|
1462
1838
|
const selection = llmsSelection(llmsConfig);
|
|
1463
1839
|
warnUnmatchedCollapse(posts, selection);
|
|
1464
|
-
const distPath =
|
|
1840
|
+
const { outDir: distPath } = resolveBuildPaths(options);
|
|
1465
1841
|
await fs.ensureDir(distPath);
|
|
1466
1842
|
const title = resolveText(siteConfig.title, lang) || "Valaxy Blog";
|
|
1467
1843
|
const description = resolveText(siteConfig.description, lang);
|
|
@@ -1490,15 +1866,19 @@ async function build$2(options) {
|
|
|
1490
1866
|
consola.debug(`[llms] Generated ${colors.dim("dist/llms-full.txt")}`);
|
|
1491
1867
|
}
|
|
1492
1868
|
if (llmsConfig.files) {
|
|
1493
|
-
await
|
|
1494
|
-
const
|
|
1869
|
+
await pMap(posts, async (post) => {
|
|
1870
|
+
const { relativeFile } = urlPathToMarkdownPath(post.urlPath);
|
|
1871
|
+
const mdPath = path.resolve(distPath, relativeFile);
|
|
1872
|
+
const relToDist = path.relative(distPath, mdPath);
|
|
1873
|
+
if (relToDist === ".." || relToDist.startsWith(`..${path.sep}`) || path.isAbsolute(relToDist))
|
|
1874
|
+
return;
|
|
1495
1875
|
await fs.ensureDir(path.dirname(mdPath));
|
|
1496
1876
|
const header = formatMetadataHeader(post);
|
|
1497
1877
|
const body = post.content.trim();
|
|
1498
1878
|
const fileContent = body ? `${header}${body}
|
|
1499
1879
|
` : `${header}`;
|
|
1500
1880
|
await fs.writeFile(mdPath, fileContent, "utf-8");
|
|
1501
|
-
})
|
|
1881
|
+
}, { concurrency: 32 });
|
|
1502
1882
|
consola.debug(`[llms] Copied ${colors.dim(posts.length.toString())} raw .md files to dist/`);
|
|
1503
1883
|
}
|
|
1504
1884
|
consola.success(`llms.txt generated. (${posts.length} pages)`);
|
|
@@ -1605,7 +1985,7 @@ function hrefToUrl(siteUrl, href) {
|
|
|
1605
1985
|
return trimmed;
|
|
1606
1986
|
const directory = trimmed.endsWith("/");
|
|
1607
1987
|
const urlPath = trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
1608
|
-
const target = directory || urlPath.endsWith(".md") ? urlPath :
|
|
1988
|
+
const target = directory || urlPath.endsWith(".md") ? urlPath : urlPathToMarkdownPath(urlPath).href;
|
|
1609
1989
|
return siteUrl ? `${siteUrl}${target}` : target;
|
|
1610
1990
|
}
|
|
1611
1991
|
function planLlmsPages(posts, config = {}) {
|
|
@@ -1681,7 +2061,7 @@ function groupLlmsEntries(params) {
|
|
|
1681
2061
|
sections.set(featuredTitle, featuredPosts.map((post) => ({
|
|
1682
2062
|
title: post.title,
|
|
1683
2063
|
description: post.description,
|
|
1684
|
-
href:
|
|
2064
|
+
href: urlPathToMarkdownPath(post.urlPath).href
|
|
1685
2065
|
})));
|
|
1686
2066
|
}
|
|
1687
2067
|
for (const post of rest) {
|
|
@@ -1690,7 +2070,7 @@ function groupLlmsEntries(params) {
|
|
|
1690
2070
|
const entry = {
|
|
1691
2071
|
title: post.title,
|
|
1692
2072
|
description: post.description,
|
|
1693
|
-
href:
|
|
2073
|
+
href: urlPathToMarkdownPath(post.urlPath).href
|
|
1694
2074
|
};
|
|
1695
2075
|
if (entries)
|
|
1696
2076
|
entries.push(entry);
|
|
@@ -1853,6 +2233,7 @@ const llmsModule = defineValaxyModule({
|
|
|
1853
2233
|
async ({ root }) => {
|
|
1854
2234
|
setEnvProd();
|
|
1855
2235
|
const options = await resolveOptions$2({ userRoot: root }, "build");
|
|
2236
|
+
await resolveEffectiveViteConfig(options, "build");
|
|
1856
2237
|
await build$2(options);
|
|
1857
2238
|
}
|
|
1858
2239
|
);
|
|
@@ -1875,46 +2256,122 @@ async function statIfExists(file) {
|
|
|
1875
2256
|
throw e;
|
|
1876
2257
|
}
|
|
1877
2258
|
}
|
|
1878
|
-
async function getCreatedTime(file) {
|
|
1879
|
-
return await getGitTimestamp(file, "created") || (await statIfExists(file))?.ctime || Date.now();
|
|
2259
|
+
async function getCreatedTime(file, cache) {
|
|
2260
|
+
return await getGitTimestamp(file, "created", cache) || (await statIfExists(file))?.ctime || Date.now();
|
|
1880
2261
|
}
|
|
1881
|
-
async function getUpdatedTime(file) {
|
|
1882
|
-
return await getGitTimestamp(file, "updated") || (await statIfExists(file))?.mtime || Date.now();
|
|
2262
|
+
async function getUpdatedTime(file, cache) {
|
|
2263
|
+
return await getGitTimestamp(file, "updated", cache) || (await statIfExists(file))?.mtime || Date.now();
|
|
1883
2264
|
}
|
|
1884
2265
|
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
2266
|
+
function assetManifestPath(options) {
|
|
2267
|
+
return join(options.tempDir || join(options.userRoot, ".valaxy"), "rss-assets.json");
|
|
2268
|
+
}
|
|
2269
|
+
function sourceKey(file, root) {
|
|
2270
|
+
const path = relative$1(root, file);
|
|
2271
|
+
if (path && path !== ".." && !path.startsWith(`..${sep$1}`) && !isAbsolute$1(path))
|
|
2272
|
+
return path.split(sep$1).join("/");
|
|
2273
|
+
}
|
|
2274
|
+
function createRssAssetsPlugin(options) {
|
|
2275
|
+
return {
|
|
2276
|
+
name: "valaxy:rss-assets",
|
|
2277
|
+
apply: "build",
|
|
2278
|
+
async writeBundle(output, bundle) {
|
|
2279
|
+
const { config } = this.environment;
|
|
2280
|
+
if (config.build.ssr || !output.dir)
|
|
2281
|
+
return;
|
|
2282
|
+
const files = /* @__PURE__ */ new Map();
|
|
2283
|
+
for (const asset of Object.values(bundle)) {
|
|
2284
|
+
if (asset.type !== "asset")
|
|
2285
|
+
continue;
|
|
2286
|
+
for (const original of asset.originalFileNames) {
|
|
2287
|
+
const key = sourceKey(resolve(config.root, original), options.userRoot);
|
|
2288
|
+
if (key)
|
|
2289
|
+
files.set(key, asset.fileName);
|
|
2290
|
+
}
|
|
2291
|
+
}
|
|
2292
|
+
const manifest = {
|
|
2293
|
+
outDir: resolve(config.root, output.dir),
|
|
2294
|
+
base: config.base,
|
|
2295
|
+
files: [...files]
|
|
2296
|
+
};
|
|
2297
|
+
await fs.outputJson(assetManifestPath(options), manifest);
|
|
2298
|
+
}
|
|
2299
|
+
};
|
|
2300
|
+
}
|
|
2301
|
+
async function readBuiltAssetUrls(options, outDir, siteUrl) {
|
|
1892
2302
|
try {
|
|
1893
|
-
|
|
1894
|
-
|
|
2303
|
+
const manifest = await fs.readJson(assetManifestPath(options));
|
|
2304
|
+
if (manifest.outDir !== outDir)
|
|
2305
|
+
return;
|
|
2306
|
+
const base = new URL(manifest.base || "./", siteUrl);
|
|
2307
|
+
return new Map(manifest.files.map(([source, emitted]) => [
|
|
2308
|
+
source,
|
|
2309
|
+
new URL(emitted.split("/").map(encodeURIComponent).join("/"), base).href
|
|
2310
|
+
]));
|
|
2311
|
+
} catch {
|
|
2312
|
+
}
|
|
2313
|
+
}
|
|
2314
|
+
function findBuiltAsset(url, markdownFile, root, assets) {
|
|
2315
|
+
let pathname = url;
|
|
2316
|
+
try {
|
|
2317
|
+
pathname = decodeURIComponent(pathname);
|
|
2318
|
+
} catch {
|
|
2319
|
+
}
|
|
2320
|
+
if (isAbsolute$1(pathname))
|
|
2321
|
+
return;
|
|
2322
|
+
const key = sourceKey(resolve(dirname(markdownFile), pathname), root);
|
|
2323
|
+
if (key)
|
|
2324
|
+
return assets.get(key);
|
|
2325
|
+
}
|
|
2326
|
+
async function readLegacyImageUrls(htmlPath, siteUrl) {
|
|
2327
|
+
const images = /* @__PURE__ */ new Map();
|
|
2328
|
+
try {
|
|
2329
|
+
if (!await fs.pathExists(htmlPath))
|
|
2330
|
+
return images;
|
|
1895
2331
|
const html = await fs.readFile(htmlPath, "utf-8");
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
2332
|
+
new Parser({
|
|
2333
|
+
onopentag(name, { src }) {
|
|
2334
|
+
if (name !== "img" || !src)
|
|
2335
|
+
return;
|
|
2336
|
+
const pathname = src.split(/[?#]/, 1)[0];
|
|
2337
|
+
const match = pathname.match(/\/assets\/([^/]+)\.[a-z0-9]+\.([a-z0-9]+)$/i);
|
|
2338
|
+
if (!match)
|
|
2339
|
+
return;
|
|
2340
|
+
const original = `${match[1]}.${match[2]}`;
|
|
2341
|
+
const url = new URL(pathname, siteUrl).href;
|
|
2342
|
+
const existing = images.get(original);
|
|
2343
|
+
images.set(original, existing !== void 0 && existing !== url ? null : url);
|
|
1907
2344
|
}
|
|
1908
|
-
}
|
|
1909
|
-
if (imageMap.size > 0) {
|
|
1910
|
-
const uniqueImageCount = imageMap.size / 2;
|
|
1911
|
-
consola.info(`[RSS] Extracted ${uniqueImageCount} image(s) from ${htmlPath}`);
|
|
1912
|
-
}
|
|
2345
|
+
}).end(html);
|
|
1913
2346
|
} catch (error) {
|
|
1914
2347
|
consola.debug(`Failed to extract image paths from ${htmlPath}:`, error);
|
|
1915
2348
|
}
|
|
1916
|
-
return
|
|
2349
|
+
return images;
|
|
1917
2350
|
}
|
|
2351
|
+
function rewriteSourceAttributes(html, resolveUrl) {
|
|
2352
|
+
const output = new MagicString(html);
|
|
2353
|
+
let isImage = false;
|
|
2354
|
+
const parser = new Parser({
|
|
2355
|
+
onopentagname(name) {
|
|
2356
|
+
isImage = name === "img";
|
|
2357
|
+
},
|
|
2358
|
+
onattribute(name, src) {
|
|
2359
|
+
if (name !== "src")
|
|
2360
|
+
return;
|
|
2361
|
+
const url = resolveUrl(src, isImage);
|
|
2362
|
+
if (url !== void 0)
|
|
2363
|
+
output.overwrite(parser.startIndex, parser.endIndex, `src="${url.replaceAll("&", "&").replaceAll('"', """).replaceAll("<", "<")}"`);
|
|
2364
|
+
}
|
|
2365
|
+
});
|
|
2366
|
+
parser.end(html);
|
|
2367
|
+
return output.toString();
|
|
2368
|
+
}
|
|
2369
|
+
|
|
2370
|
+
const markdown = createMarkdownExit({
|
|
2371
|
+
html: true,
|
|
2372
|
+
breaks: true,
|
|
2373
|
+
linkify: true
|
|
2374
|
+
});
|
|
1918
2375
|
async function build$1(options) {
|
|
1919
2376
|
consola.start("RSS Generating ...");
|
|
1920
2377
|
const { config } = options;
|
|
@@ -1947,7 +2404,7 @@ async function build$1(options) {
|
|
|
1947
2404
|
feedLinks
|
|
1948
2405
|
};
|
|
1949
2406
|
const DOMAIN = siteConfig.url.slice(0, -1);
|
|
1950
|
-
const files = await glob("pages/posts/**/*.md", { cwd: options.userRoot, absolute: true });
|
|
2407
|
+
const files = options.config.loaders?.length ? [...(await discoverPageFiles(options.userRoot, ["posts/**/*.md"])).values()] : await glob("pages/posts/**/*.md", { cwd: options.userRoot, absolute: true, onlyFiles: true });
|
|
1951
2408
|
const posts = await getPosts({
|
|
1952
2409
|
author,
|
|
1953
2410
|
files,
|
|
@@ -1967,13 +2424,12 @@ async function getPosts(params, options) {
|
|
|
1967
2424
|
const siteConfig = config.siteConfig;
|
|
1968
2425
|
const lang = siteConfig.lang || "en";
|
|
1969
2426
|
const { files, author, DOMAIN } = params;
|
|
1970
|
-
const
|
|
2427
|
+
const rawPosts = await pMap(files, async (i) => {
|
|
1971
2428
|
const raw = await readFile(i, "utf-8");
|
|
1972
2429
|
const { data, content, excerpt } = matter(raw, matterOptions);
|
|
1973
2430
|
const frontmatter = { ...siteConfig.frontmatter, ...data };
|
|
1974
2431
|
return { data: frontmatter, content, excerpt, path: i };
|
|
1975
|
-
});
|
|
1976
|
-
const rawPosts = await Promise.all(readFilePromises);
|
|
2432
|
+
}, { concurrency: 20 });
|
|
1977
2433
|
const draftPosts = [];
|
|
1978
2434
|
const filteredPosts = rawPosts.filter((p) => {
|
|
1979
2435
|
const { data } = p;
|
|
@@ -1994,7 +2450,12 @@ async function getPosts(params, options) {
|
|
|
1994
2450
|
consola.warn(`[rss] Skipped ${colors.yellow(String(draftPosts.length))} draft post(s):
|
|
1995
2451
|
${draftPosts.map((p) => ` ${colors.dim("-")} ${colors.dim(p)}`).join("\n")}`);
|
|
1996
2452
|
}
|
|
2453
|
+
const gitTimestampCache = getGitTimestampCache(options);
|
|
1997
2454
|
const posts = [];
|
|
2455
|
+
const siteUrl = `${DOMAIN}/`;
|
|
2456
|
+
const { outDir } = resolveBuildPaths(options);
|
|
2457
|
+
const extractImages = options.config.modules.rss.extractImagePathsFromHTML;
|
|
2458
|
+
const builtAssets = extractImages ? await readBuiltAssetUrls(options, outDir, siteUrl) : void 0;
|
|
1998
2459
|
for (const rawPost of filteredPosts) {
|
|
1999
2460
|
const { data, path } = rawPost;
|
|
2000
2461
|
const content = stripEncryptedContent(rawPost.content);
|
|
@@ -2003,43 +2464,38 @@ ${draftPosts.map((p) => ` ${colors.dim("-")} ${colors.dim(p)}`).join("\n")}`);
|
|
|
2003
2464
|
const manualExcerpt = tObject(data.excerpt, lang);
|
|
2004
2465
|
const summaryLength = siteConfig.excerpt?.length || 200;
|
|
2005
2466
|
if (!data.date)
|
|
2006
|
-
data.date = await getCreatedTime(path);
|
|
2467
|
+
data.date = await getCreatedTime(path, gitTimestampCache);
|
|
2007
2468
|
if (siteConfig.lastUpdated) {
|
|
2008
2469
|
if (!data.updated)
|
|
2009
|
-
data.updated = await getUpdatedTime(path);
|
|
2470
|
+
data.updated = await getUpdatedTime(path, gitTimestampCache);
|
|
2010
2471
|
}
|
|
2011
2472
|
const fullText = options.config.modules.rss.fullText;
|
|
2012
2473
|
const rssContent = fullText ? content : excerpt || content.slice(0, 100);
|
|
2013
|
-
const relativePath = relative$1(join(options.userRoot, "pages"), path);
|
|
2014
|
-
const urlPath = relativePath
|
|
2474
|
+
const relativePath = getPagePath(path, options.userRoot) || relative$1(join(options.userRoot, "pages"), path).replace(/\\/g, "/");
|
|
2475
|
+
const urlPath = pagePathToRoute(relativePath);
|
|
2015
2476
|
const link = `${DOMAIN}/${urlPath}`;
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
}
|
|
2034
|
-
if (src.startsWith("http://") || src.startsWith("https://")) {
|
|
2035
|
-
return _fullMatch;
|
|
2036
|
-
}
|
|
2037
|
-
if (src.startsWith("/")) {
|
|
2038
|
-
return `src="${DOMAIN}${src}"`;
|
|
2477
|
+
let legacyImages;
|
|
2478
|
+
if (extractImages && !builtAssets) {
|
|
2479
|
+
let htmlPath = resolve(outDir, `${urlPath}.html`);
|
|
2480
|
+
if (!await fs.pathExists(htmlPath) && relativePath.endsWith("/index.md"))
|
|
2481
|
+
htmlPath = resolve(outDir, urlPath, "index.html");
|
|
2482
|
+
legacyImages = await readLegacyImageUrls(htmlPath, siteUrl);
|
|
2483
|
+
}
|
|
2484
|
+
const html = rewriteSourceAttributes(markdown.render(rssContent), (src, isImage) => {
|
|
2485
|
+
if (!src || /^(?:\/\/|#|[a-z][\w+.-]*:)/i.test(src))
|
|
2486
|
+
return;
|
|
2487
|
+
if (src.startsWith("/"))
|
|
2488
|
+
return `${DOMAIN}${src}`;
|
|
2489
|
+
if (isImage) {
|
|
2490
|
+
const pathname = src.split(/[?#]/, 1)[0];
|
|
2491
|
+
const mapped = builtAssets ? findBuiltAsset(pathname, path, options.userRoot, builtAssets) : legacyImages?.get(pathname.replace(/^\.\//, ""));
|
|
2492
|
+
if (mapped)
|
|
2493
|
+
return mapped + src.slice(pathname.length);
|
|
2039
2494
|
}
|
|
2040
|
-
const
|
|
2495
|
+
const postDir = relativePath.split("/").slice(0, -1).join("/");
|
|
2496
|
+
const postDirUrl = postDir ? `${DOMAIN}/${postDir}` : DOMAIN;
|
|
2041
2497
|
const cleanSrc = src.startsWith("./") ? src.slice(2) : src;
|
|
2042
|
-
return
|
|
2498
|
+
return `${postDirUrl}/${cleanSrc}`;
|
|
2043
2499
|
});
|
|
2044
2500
|
if (data.image?.startsWith("/"))
|
|
2045
2501
|
data.image = DOMAIN + data.image;
|
|
@@ -2075,9 +2531,11 @@ ${draftPosts.map((p) => ` ${colors.dim("-")} ${colors.dim(p)}`).join("\n")}`);
|
|
|
2075
2531
|
async function writeFeed(feedOptions, posts, options, feedNameMap) {
|
|
2076
2532
|
const feed = new Feed(feedOptions);
|
|
2077
2533
|
posts.forEach((item) => feed.addItem(item));
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2534
|
+
const { outDir: distDir, publicDir: publicFolder } = resolveBuildPaths(options);
|
|
2535
|
+
await fs.ensureDir(distDir);
|
|
2536
|
+
if (publicFolder !== false)
|
|
2537
|
+
await fs.ensureDir(publicFolder);
|
|
2538
|
+
const outLabel = basename(distDir) || "dist";
|
|
2081
2539
|
const { config } = options;
|
|
2082
2540
|
const siteConfig = config.siteConfig;
|
|
2083
2541
|
const now = dayjs().format("YYYY-MM-DD HH:mm:ss zzz");
|
|
@@ -2089,33 +2547,38 @@ async function writeFeed(feedOptions, posts, options, feedNameMap) {
|
|
|
2089
2547
|
const types = ["rss", "atom", "json"];
|
|
2090
2548
|
for (const type of types) {
|
|
2091
2549
|
let data = "";
|
|
2092
|
-
const distFeedPath = `${
|
|
2550
|
+
const distFeedPath = `${distDir}/${feedNameMap[type]}`;
|
|
2093
2551
|
if (type === "rss")
|
|
2094
2552
|
data = feed.rss2();
|
|
2095
2553
|
else if (type === "atom")
|
|
2096
2554
|
data = feed.atom1();
|
|
2097
2555
|
else if (type === "json")
|
|
2098
2556
|
data = feed.json1();
|
|
2557
|
+
await fs.ensureDir(dirname(distFeedPath));
|
|
2099
2558
|
await fs.writeFile(distFeedPath, data, "utf-8");
|
|
2100
2559
|
consola.debug(`[${colors.cyan(type)}] dist: ${colors.dim(distFeedPath)}`);
|
|
2101
|
-
tableData.push([colors.cyan(type), colors.yellow(
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2560
|
+
tableData.push([colors.cyan(type), colors.yellow(outLabel), colors.dim(distFeedPath)]);
|
|
2561
|
+
if (publicFolder !== false) {
|
|
2562
|
+
const publicFeedPath = resolve(publicFolder, feedNameMap[type]);
|
|
2563
|
+
const publicRelativeFile = relative$1(options.userRoot, publicFeedPath).replace(/\\/g, "/");
|
|
2564
|
+
await fs.ensureDir(dirname(publicFeedPath));
|
|
2565
|
+
await fs.writeFile(publicFeedPath, data, "utf-8");
|
|
2566
|
+
consola.debug(`[${colors.cyan(type)}] public: ${colors.dim(publicFeedPath)}`);
|
|
2567
|
+
tableData.push(["", colors.green("public"), colors.dim(publicFeedPath)]);
|
|
2568
|
+
if (publicRelativeFile && !publicRelativeFile.startsWith("..")) {
|
|
2569
|
+
try {
|
|
2570
|
+
const gitignorePath = resolve(options.userRoot, ".gitignore");
|
|
2571
|
+
const gitignore = await fs.readFile(gitignorePath, "utf-8");
|
|
2572
|
+
if (!gitignore.includes(publicRelativeFile)) {
|
|
2573
|
+
await fs.appendFile(gitignorePath, `
|
|
2113
2574
|
# valaxy rss
|
|
2114
|
-
${
|
|
2575
|
+
${publicRelativeFile}
|
|
2115
2576
|
`);
|
|
2116
|
-
|
|
2577
|
+
consola.success(`Add ${colors.dim(publicRelativeFile)} to ${colors.dim(".gitignore")}`);
|
|
2578
|
+
}
|
|
2579
|
+
} catch {
|
|
2580
|
+
}
|
|
2117
2581
|
}
|
|
2118
|
-
} catch {
|
|
2119
2582
|
}
|
|
2120
2583
|
}
|
|
2121
2584
|
console.log(table(tableData, {
|
|
@@ -2148,6 +2611,7 @@ const rssModule = defineValaxyModule({
|
|
|
2148
2611
|
async ({ root }) => {
|
|
2149
2612
|
setEnvProd();
|
|
2150
2613
|
const options = await resolveOptions$2({ userRoot: root }, "build");
|
|
2614
|
+
await resolveEffectiveViteConfig(options, "build");
|
|
2151
2615
|
await build$1(options);
|
|
2152
2616
|
}
|
|
2153
2617
|
);
|
|
@@ -3632,118 +4096,111 @@ export default new Map([${entries.join(",\n")}])`;
|
|
|
3632
4096
|
};
|
|
3633
4097
|
}
|
|
3634
4098
|
|
|
3635
|
-
function
|
|
3636
|
-
|
|
3637
|
-
|
|
3638
|
-
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
|
|
3642
|
-
|
|
3643
|
-
var done = 0;
|
|
3644
|
-
var observer = new MutationObserver(check);
|
|
3645
|
-
var timer = maxDuration ? setTimeout(reveal, maxDuration) : void 0;
|
|
3646
|
-
function reveal() {
|
|
3647
|
-
if (done) return;
|
|
3648
|
-
done = 1;
|
|
3649
|
-
observer.disconnect();
|
|
3650
|
-
clearTimeout(timer);
|
|
3651
|
-
document.removeEventListener("load", check, true);
|
|
3652
|
-
removeEventListener("load", reveal);
|
|
3653
|
-
var s = document.getElementById("valaxy-fouc");
|
|
3654
|
-
if (s) s.remove();
|
|
4099
|
+
function resolveImage(src, source) {
|
|
4100
|
+
if (!src || /^(?:\/|#|[a-z][\w+.-]*:)/i.test(src))
|
|
4101
|
+
return;
|
|
4102
|
+
const [pathname] = src.split(/[?#]/);
|
|
4103
|
+
let filename = pathname;
|
|
4104
|
+
try {
|
|
4105
|
+
filename = decodeURIComponent(pathname);
|
|
4106
|
+
} catch {
|
|
3655
4107
|
}
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
|
|
3662
|
-
}
|
|
3663
|
-
|
|
4108
|
+
if (isAbsolute(filename))
|
|
4109
|
+
return;
|
|
4110
|
+
const file = resolve$1(dirname$1(source), filename);
|
|
4111
|
+
if (/[?#]/.test(file))
|
|
4112
|
+
return;
|
|
4113
|
+
try {
|
|
4114
|
+
if (statSync(file, { throwIfNoEntry: false })?.isFile())
|
|
4115
|
+
return { file, suffix: src.slice(pathname.length) };
|
|
4116
|
+
} catch {
|
|
3664
4117
|
}
|
|
3665
|
-
observer.observe(document.documentElement, { childList: true });
|
|
3666
|
-
observer.observe(document.head, {
|
|
3667
|
-
childList: true,
|
|
3668
|
-
subtree: true,
|
|
3669
|
-
attributes: true,
|
|
3670
|
-
attributeFilter: ["media", "rel", "disabled"]
|
|
3671
|
-
});
|
|
3672
|
-
document.addEventListener("load", check, true);
|
|
3673
|
-
addEventListener("load", reveal);
|
|
3674
4118
|
}
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
4119
|
+
function collectImageEdits(html, source, importImage) {
|
|
4120
|
+
const edits = [];
|
|
4121
|
+
let tag = "";
|
|
4122
|
+
const parser = new Parser({
|
|
4123
|
+
onopentagname(name) {
|
|
4124
|
+
tag = name;
|
|
4125
|
+
},
|
|
4126
|
+
onattribute(name, src) {
|
|
4127
|
+
if (tag !== "img" || name !== "src")
|
|
4128
|
+
return;
|
|
4129
|
+
const image = resolveImage(src, source);
|
|
4130
|
+
if (!image)
|
|
4131
|
+
return;
|
|
4132
|
+
const { startIndex, endIndex } = parser;
|
|
4133
|
+
const asset = importImage(image.file, !!image.suffix);
|
|
4134
|
+
edits.push(`[${startIndex}, ${endIndex}, ${JSON.stringify(html.slice(startIndex, endIndex))}, ${asset}, ${JSON.stringify(image.suffix)}]`);
|
|
4135
|
+
}
|
|
3687
4136
|
});
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
4137
|
+
parser.end(html);
|
|
4138
|
+
return edits;
|
|
4139
|
+
}
|
|
4140
|
+
function createExcerptAssets() {
|
|
4141
|
+
let tree;
|
|
4142
|
+
const plugin = {
|
|
4143
|
+
name: "valaxy:excerpt-assets",
|
|
4144
|
+
transform(code, id) {
|
|
4145
|
+
if (id !== "\0vue-router/auto-routes" || !tree)
|
|
4146
|
+
return;
|
|
4147
|
+
const imports = /* @__PURE__ */ new Map();
|
|
4148
|
+
function importImage(file, forceFile) {
|
|
4149
|
+
const request = `${toAtFS(file)}?url${forceFile ? "&no-inline" : ""}`;
|
|
4150
|
+
const existing = imports.get(request);
|
|
4151
|
+
if (existing)
|
|
4152
|
+
return existing;
|
|
4153
|
+
const name = `__valaxy_excerpt_asset_${imports.size}`;
|
|
4154
|
+
imports.set(request, name);
|
|
4155
|
+
return name;
|
|
4156
|
+
}
|
|
4157
|
+
const entries = [];
|
|
4158
|
+
for (const route of tree) {
|
|
4159
|
+
const source = route.components.get("default");
|
|
4160
|
+
const { excerpt } = route.meta;
|
|
4161
|
+
if (typeof route.name !== "string" || !source?.endsWith(".md") || typeof excerpt !== "string")
|
|
4162
|
+
continue;
|
|
4163
|
+
const edits = collectImageEdits(excerpt, source, importImage);
|
|
4164
|
+
if (edits.length)
|
|
4165
|
+
entries.push(`[${JSON.stringify(route.name)}, [${edits.reverse().join(", ")}]]`);
|
|
4166
|
+
}
|
|
4167
|
+
if (!entries.length)
|
|
4168
|
+
return;
|
|
4169
|
+
const output = new MagicString(code);
|
|
4170
|
+
output.prepend(`${Array.from(imports, ([request, name]) => `import ${name} from ${JSON.stringify(request)}`).join("\n")}
|
|
4171
|
+
`);
|
|
4172
|
+
output.append(`
|
|
4173
|
+
{
|
|
4174
|
+
const editsByName = new Map([${entries.join(",\n")}])
|
|
4175
|
+
function updateExcerpts(records) {
|
|
4176
|
+
for (const route of records) {
|
|
4177
|
+
const edits = editsByName.get(route.name)
|
|
4178
|
+
let html = route.meta?.excerpt
|
|
4179
|
+
if (edits && typeof html === 'string') {
|
|
4180
|
+
for (const [start, end, original, url, suffix] of edits) {
|
|
4181
|
+
// A definePage() export can override the metadata supplied by the route tree.
|
|
4182
|
+
if (html.slice(start, end) !== original) continue
|
|
4183
|
+
const src = (suffix ? url.replace(/\\?no-inline$/, '') + suffix : url)
|
|
4184
|
+
.replaceAll('&', '&').replaceAll('"', '"').replaceAll('<', '<')
|
|
4185
|
+
html = html.slice(0, start) + 'src="' + src + '"' + html.slice(end)
|
|
4186
|
+
}
|
|
4187
|
+
route.meta.excerpt = html
|
|
4188
|
+
}
|
|
4189
|
+
if (route.children) updateExcerpts(route.children)
|
|
4190
|
+
}
|
|
3693
4191
|
}
|
|
3694
|
-
|
|
4192
|
+
updateExcerpts(routes)
|
|
3695
4193
|
}
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
;(function () {
|
|
3707
|
-
const prefersDark =
|
|
3708
|
-
window.matchMedia &&
|
|
3709
|
-
window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
3710
|
-
const setting = localStorage.getItem('vueuse-color-scheme') || 'auto'
|
|
3711
|
-
if (setting === 'dark' || (prefersDark && setting !== 'light'))
|
|
3712
|
-
document.documentElement.classList.toggle('dark', true)
|
|
3713
|
-
})()
|
|
3714
|
-
<\/script>
|
|
3715
|
-
`;
|
|
3716
|
-
head += `<style type="text/css">
|
|
3717
|
-
:root { color-scheme: light dark; --va-c-bg: #fff; }
|
|
3718
|
-
html.dark { --va-c-bg: #000; }
|
|
3719
|
-
html { background-color: var(--va-c-bg); }
|
|
3720
|
-
</style>`;
|
|
3721
|
-
}
|
|
3722
|
-
const foucGuard = config.build?.foucGuard ?? {};
|
|
3723
|
-
const foucEnabled = foucGuard.enabled ?? true;
|
|
3724
|
-
const foucMaxDuration = foucGuard.maxDuration ?? 5e3;
|
|
3725
|
-
if (foucEnabled)
|
|
3726
|
-
head += foucGuardHtml(foucMaxDuration);
|
|
3727
|
-
if (config.siteConfig.lang) {
|
|
3728
|
-
head += `
|
|
3729
|
-
<script>
|
|
3730
|
-
const locale = localStorage.getItem('valaxy-locale') || '${config.siteConfig.lang}';
|
|
3731
|
-
document.documentElement.setAttribute('lang', locale);
|
|
3732
|
-
<\/script>
|
|
3733
|
-
`;
|
|
3734
|
-
}
|
|
3735
|
-
for (const root of roots) {
|
|
3736
|
-
const path = join(root, "index.html");
|
|
3737
|
-
if (!fs.existsSync(path))
|
|
3738
|
-
continue;
|
|
3739
|
-
const indexHtml = await fs.readFile(path, "utf-8");
|
|
3740
|
-
head += `
|
|
3741
|
-
${(indexHtml.match(/<head>([\s\S]*?)<\/head>/i)?.[1] || "").trim()}`;
|
|
3742
|
-
body += `
|
|
3743
|
-
${(indexHtml.match(/<body>([\s\S]*?)<\/body>/i)?.[1] || "").trim()}`;
|
|
3744
|
-
}
|
|
3745
|
-
main = main.replace("__ENTRY__", toAtFS(join(clientRoot, "main.ts"))).replace("<!-- head -->", head).replace("<!-- body -->", body);
|
|
3746
|
-
return main;
|
|
4194
|
+
`);
|
|
4195
|
+
return { code: output.toString(), map: output.generateMap({ hires: true }) };
|
|
4196
|
+
}
|
|
4197
|
+
};
|
|
4198
|
+
return {
|
|
4199
|
+
setRoutes(root) {
|
|
4200
|
+
tree = root;
|
|
4201
|
+
},
|
|
4202
|
+
plugin
|
|
4203
|
+
};
|
|
3747
4204
|
}
|
|
3748
4205
|
|
|
3749
4206
|
const DEVTOOLS_SEARCH_SHORTCUT_GUARD = `window.addEventListener('keydown', function (event) {
|
|
@@ -3838,13 +4295,17 @@ function createConfigPlugin(options) {
|
|
|
3838
4295
|
const valaxyDefine = getDefine();
|
|
3839
4296
|
const userDefine = config.define || {};
|
|
3840
4297
|
const mergedDefine = { ...valaxyDefine, ...userDefine };
|
|
4298
|
+
const resolvedPublicDir = resolvePublicDir(
|
|
4299
|
+
options.userRoot,
|
|
4300
|
+
config.publicDir !== void 0 ? config.publicDir : options.publicDir !== void 0 ? options.publicDir : options.config.vite?.publicDir
|
|
4301
|
+
);
|
|
3841
4302
|
const injection = {
|
|
3842
4303
|
// root: options.userRoot,
|
|
3843
4304
|
// can not transform valaxy/client/*.ts when use userRoot
|
|
3844
4305
|
root: options.clientRoot,
|
|
3845
4306
|
// cacheDir: join(options.userRoot, 'node_modules/.vite'),
|
|
3846
4307
|
cacheDir: join(options.userRoot, "node_modules/.valaxy/cache"),
|
|
3847
|
-
publicDir:
|
|
4308
|
+
publicDir: resolvedPublicDir,
|
|
3848
4309
|
define: mergedDefine,
|
|
3849
4310
|
resolve: {
|
|
3850
4311
|
alias: await getAlias(options),
|
|
@@ -4489,7 +4950,7 @@ The language '${lang}' is not loaded, falling back to '${defaultLang}' for synta
|
|
|
4489
4950
|
};
|
|
4490
4951
|
const restoreMustache = (s) => {
|
|
4491
4952
|
mustaches.forEach((marker, match) => {
|
|
4492
|
-
s = s.replaceAll(marker, match);
|
|
4953
|
+
s = s.replaceAll(marker, () => match);
|
|
4493
4954
|
});
|
|
4494
4955
|
return s;
|
|
4495
4956
|
};
|
|
@@ -4883,7 +5344,7 @@ function imagePlugin(md) {
|
|
|
4883
5344
|
if (url && !EXTERNAL_URL_RE.test(url)) {
|
|
4884
5345
|
if (!/^\.?\//.test(url))
|
|
4885
5346
|
url = `./${url}`;
|
|
4886
|
-
token.attrSet("src",
|
|
5347
|
+
token.attrSet("src", safeDecodeURIComponent(url));
|
|
4887
5348
|
}
|
|
4888
5349
|
return imageRule(tokens, idx, options, env, self);
|
|
4889
5350
|
};
|
|
@@ -4933,13 +5394,13 @@ function linkPlugin(md, externalAttrs, resolveBase) {
|
|
|
4933
5394
|
if (env.cleanUrls === "disabled" && !cleanUrl.endsWith(".html") && !cleanUrl.endsWith("/")) {
|
|
4934
5395
|
cleanUrl += ".html";
|
|
4935
5396
|
}
|
|
4936
|
-
const parsed =
|
|
4937
|
-
url = cleanUrl + parsed.search + parsed.hash;
|
|
5397
|
+
const parsed = safeParseUrl(url, "http://a.com");
|
|
5398
|
+
url = cleanUrl + (parsed ? parsed.search + parsed.hash : "");
|
|
4938
5399
|
}
|
|
4939
5400
|
if (!url.startsWith("/") && !/^\.\//.test(url))
|
|
4940
5401
|
url = `./${url}`;
|
|
4941
5402
|
pushLink(url.replace(/\.html$/, ""), env);
|
|
4942
|
-
return
|
|
5403
|
+
return safeDecodeURI(url);
|
|
4943
5404
|
}
|
|
4944
5405
|
function pushLink(link, env) {
|
|
4945
5406
|
const links = env.links || (env.links = []);
|
|
@@ -5052,6 +5513,42 @@ function containerPlugin(md, containerOptions = {}) {
|
|
|
5052
5513
|
});
|
|
5053
5514
|
md.use(...createCodeGroup(md));
|
|
5054
5515
|
}
|
|
5516
|
+
const NAMED_HTML_ENTITIES = /* @__PURE__ */ new Map([
|
|
5517
|
+
["amp", "&"],
|
|
5518
|
+
["AMP", "&"],
|
|
5519
|
+
["lt", "<"],
|
|
5520
|
+
["LT", "<"],
|
|
5521
|
+
["gt", ">"],
|
|
5522
|
+
["GT", ">"],
|
|
5523
|
+
["quot", '"'],
|
|
5524
|
+
["QUOT", '"'],
|
|
5525
|
+
["apos", "'"],
|
|
5526
|
+
["nbsp", "\xA0"],
|
|
5527
|
+
["copy", "\xA9"],
|
|
5528
|
+
["COPY", "\xA9"],
|
|
5529
|
+
["reg", "\xAE"],
|
|
5530
|
+
["REG", "\xAE"],
|
|
5531
|
+
["trade", "\u2122"],
|
|
5532
|
+
["mdash", "\u2014"],
|
|
5533
|
+
["ndash", "\u2013"],
|
|
5534
|
+
["hellip", "\u2026"]
|
|
5535
|
+
]);
|
|
5536
|
+
function decodeHtmlEntities(input) {
|
|
5537
|
+
return input.replace(/&(?:#(\d+)|#x([0-9a-f]+)|([a-z][a-z0-9]+));/gi, (match, dec, hex, named) => {
|
|
5538
|
+
if (dec !== void 0 || hex !== void 0) {
|
|
5539
|
+
const code = Number.parseInt(dec ?? hex, dec !== void 0 ? 10 : 16);
|
|
5540
|
+
if (!Number.isFinite(code) || code <= 0 || code > 1114111 || code >= 55296 && code <= 57343)
|
|
5541
|
+
return "\uFFFD";
|
|
5542
|
+
return String.fromCodePoint(code);
|
|
5543
|
+
}
|
|
5544
|
+
if (named) {
|
|
5545
|
+
const resolved = NAMED_HTML_ENTITIES.get(named);
|
|
5546
|
+
if (resolved !== void 0)
|
|
5547
|
+
return resolved;
|
|
5548
|
+
}
|
|
5549
|
+
return match;
|
|
5550
|
+
});
|
|
5551
|
+
}
|
|
5055
5552
|
function createCodeGroup(md) {
|
|
5056
5553
|
return [
|
|
5057
5554
|
containerCompat,
|
|
@@ -5069,8 +5566,10 @@ function createCodeGroup(md) {
|
|
|
5069
5566
|
isHtml
|
|
5070
5567
|
);
|
|
5071
5568
|
if (title) {
|
|
5569
|
+
const rawTitle = isHtml ? decodeHtmlEntities(title) : title;
|
|
5570
|
+
const escapedTitle = md.utils.escapeHtml(rawTitle);
|
|
5072
5571
|
tabs += `<input type="radio" name="group-${idx}" id="tab-${i}" ${checked}/>`;
|
|
5073
|
-
tabs += `<label data-title="${
|
|
5572
|
+
tabs += `<label v-pre data-title="${escapedTitle}" for="tab-${i}">${escapedTitle}</label>`;
|
|
5074
5573
|
if (checked && !isHtml)
|
|
5075
5574
|
tokens[i].info += " active";
|
|
5076
5575
|
checked = "";
|
|
@@ -5336,6 +5835,19 @@ function lineNumberPlugin(md, enable = false) {
|
|
|
5336
5835
|
});
|
|
5337
5836
|
}
|
|
5338
5837
|
|
|
5838
|
+
function statSnippetFile(src) {
|
|
5839
|
+
try {
|
|
5840
|
+
const stat = fs.statSync(src, { throwIfNoEntry: false });
|
|
5841
|
+
if (!stat)
|
|
5842
|
+
return "missing";
|
|
5843
|
+
return stat.isFile() ? "file" : "invalid";
|
|
5844
|
+
} catch (error) {
|
|
5845
|
+
const code = error.code;
|
|
5846
|
+
if (code === "ENOENT" || code === "ENOTDIR")
|
|
5847
|
+
return "missing";
|
|
5848
|
+
throw error;
|
|
5849
|
+
}
|
|
5850
|
+
}
|
|
5339
5851
|
const rawPathRegexp = /^(.+?(?:\.([a-z0-9]+))?)(#[\w-]+)?(?: ?\{(\d+(?:[,-]\d+)*)? ?(\S+)?\})? ?(?:\[(.+)\])?$/;
|
|
5340
5852
|
function rawPathToToken(rawPath) {
|
|
5341
5853
|
const [
|
|
@@ -5438,13 +5950,24 @@ function snippetPlugin(md, srcDir = "") {
|
|
|
5438
5950
|
return fence(...args);
|
|
5439
5951
|
if (includes)
|
|
5440
5952
|
includes.push(src);
|
|
5441
|
-
const
|
|
5442
|
-
if (
|
|
5443
|
-
token.content =
|
|
5953
|
+
const snippetStatus = statSnippetFile(src);
|
|
5954
|
+
if (snippetStatus !== "file") {
|
|
5955
|
+
token.content = snippetStatus === "missing" ? `Code snippet path not found: ${src}` : `Invalid code snippet option`;
|
|
5444
5956
|
token.info = "";
|
|
5445
5957
|
return fence(...args);
|
|
5446
5958
|
}
|
|
5447
|
-
let content
|
|
5959
|
+
let content;
|
|
5960
|
+
try {
|
|
5961
|
+
content = fs.readFileSync(src, "utf8");
|
|
5962
|
+
} catch (error) {
|
|
5963
|
+
const code = error.code;
|
|
5964
|
+
if (code === "ENOENT" || code === "ENOTDIR") {
|
|
5965
|
+
token.content = `Code snippet path not found: ${src}`;
|
|
5966
|
+
token.info = "";
|
|
5967
|
+
return fence(...args);
|
|
5968
|
+
}
|
|
5969
|
+
throw error;
|
|
5970
|
+
}
|
|
5448
5971
|
if (regionName) {
|
|
5449
5972
|
const lines = content.split(/\r?\n/);
|
|
5450
5973
|
const region = findRegion(lines, regionName);
|
|
@@ -6881,10 +7404,17 @@ function createTransformCodeBlock(options) {
|
|
|
6881
7404
|
};
|
|
6882
7405
|
}
|
|
6883
7406
|
|
|
7407
|
+
function isInsideDir(baseDir, targetPath) {
|
|
7408
|
+
const rel = path$1.relative(baseDir, targetPath);
|
|
7409
|
+
return rel !== ".." && !rel.startsWith("../") && !path$1.isAbsolute(rel);
|
|
7410
|
+
}
|
|
6884
7411
|
function createScanDeadLinks(options) {
|
|
6885
7412
|
const srcDir = path$1.resolve(options.userRoot, "pages");
|
|
6886
7413
|
const { ignoreDeadLinks } = options.config.build;
|
|
6887
|
-
const publicDir =
|
|
7414
|
+
const publicDir = resolvePublicDir(
|
|
7415
|
+
options.userRoot,
|
|
7416
|
+
options.publicDir !== void 0 ? options.publicDir : options.config.vite?.publicDir
|
|
7417
|
+
);
|
|
6888
7418
|
return (code, context) => {
|
|
6889
7419
|
const { id, fileInfo } = context;
|
|
6890
7420
|
const { links = [] } = fileInfo || {};
|
|
@@ -6914,21 +7444,21 @@ function createScanDeadLinks(options) {
|
|
|
6914
7444
|
});
|
|
6915
7445
|
}
|
|
6916
7446
|
if (links) {
|
|
6917
|
-
const dir = path$1.dirname(file);
|
|
6918
7447
|
for (let url of links) {
|
|
6919
|
-
const
|
|
6920
|
-
if (!treatAsHtml(pathname))
|
|
7448
|
+
const parsed = safeParseUrl(url, "http://a.com");
|
|
7449
|
+
if (!parsed || !treatAsHtml(parsed.pathname))
|
|
6921
7450
|
continue;
|
|
6922
7451
|
url = url.replace(/[?#].*$/, "").replace(/\.(html|md)$/, "");
|
|
6923
7452
|
if (url.endsWith("/"))
|
|
6924
7453
|
url += `index`;
|
|
6925
|
-
const resolved =
|
|
7454
|
+
const resolved = safeDecodeURIComponent(
|
|
6926
7455
|
slash$1(
|
|
6927
7456
|
url.startsWith("/") ? url.slice(1) : path$1.normalize(path$1.join(path$1.dirname(logicalFile), url))
|
|
6928
7457
|
)
|
|
6929
7458
|
// /index => /
|
|
6930
7459
|
).replace(/(^|\/)index$/, "");
|
|
6931
|
-
|
|
7460
|
+
const publicCandidate = publicDir ? path$1.resolve(publicDir, `${resolved}.html`) : null;
|
|
7461
|
+
if (!routes.has(resolved) && !resolvePageFile(`${resolved}.vue`, options.userRoot) && !resolvePageFile(path$1.join(resolved, "index.vue"), options.userRoot) && !(publicDir && publicCandidate && isInsideDir(publicDir, publicCandidate) && fs.existsSync(publicCandidate)) && !shouldIgnoreDeadLink(url)) {
|
|
6932
7462
|
recordDeadLink(url);
|
|
6933
7463
|
}
|
|
6934
7464
|
}
|
|
@@ -6946,7 +7476,7 @@ function createTransformEncrypt(options) {
|
|
|
6946
7476
|
let getValaxyDecryptTemplate = function(options2) {
|
|
6947
7477
|
return [
|
|
6948
7478
|
"<ClientOnly>",
|
|
6949
|
-
`<ValaxyDecrypt :encrypted-content="${options2.encryptedContent}" hint="${options2.hint || ""}" />`,
|
|
7479
|
+
`<ValaxyDecrypt :encrypted-content="${options2.encryptedContent}" hint="${escapeHtml(options2.hint || "")}" />`,
|
|
6950
7480
|
"</ClientOnly>"
|
|
6951
7481
|
].join("");
|
|
6952
7482
|
};
|
|
@@ -6987,26 +7517,47 @@ function createTransformEncrypt(options) {
|
|
|
6987
7517
|
}
|
|
6988
7518
|
}
|
|
6989
7519
|
if (password) {
|
|
6990
|
-
const
|
|
6991
|
-
const
|
|
6992
|
-
const
|
|
6993
|
-
const
|
|
6994
|
-
|
|
6995
|
-
|
|
6996
|
-
|
|
6997
|
-
|
|
6998
|
-
|
|
6999
|
-
|
|
7000
|
-
|
|
7001
|
-
|
|
7002
|
-
|
|
7003
|
-
encryptedContent
|
|
7004
|
-
|
|
7005
|
-
|
|
7006
|
-
|
|
7007
|
-
|
|
7008
|
-
|
|
7009
|
-
|
|
7520
|
+
const { parse: parseSfc, parseCache } = await import('vue/compiler-sfc');
|
|
7521
|
+
const parsed = parseSfc(code, { filename: id, sourceMap: false });
|
|
7522
|
+
const templateLoc = parsed.descriptor.template ? { start: parsed.descriptor.template.loc.start.offset, end: parsed.descriptor.template.loc.end.offset } : null;
|
|
7523
|
+
const scriptSetupLoc = parsed.descriptor.scriptSetup ? { start: parsed.descriptor.scriptSetup.loc.start.offset, end: parsed.descriptor.scriptSetup.loc.end.offset } : null;
|
|
7524
|
+
for (const [key, entry] of parseCache) {
|
|
7525
|
+
if (entry === parsed) {
|
|
7526
|
+
parseCache.delete(key);
|
|
7527
|
+
break;
|
|
7528
|
+
}
|
|
7529
|
+
}
|
|
7530
|
+
const patches = [];
|
|
7531
|
+
if (templateLoc) {
|
|
7532
|
+
const content = code.slice(templateLoc.start, templateLoc.end);
|
|
7533
|
+
const encryptedContent = await encryptContent(content, {
|
|
7534
|
+
password,
|
|
7535
|
+
iv: encrypt.iv,
|
|
7536
|
+
salt: encrypt.salt
|
|
7537
|
+
});
|
|
7538
|
+
frontmatter.encryptedContent = encryptedContent;
|
|
7539
|
+
frontmatter.encrypt = true;
|
|
7540
|
+
delete frontmatter.password;
|
|
7541
|
+
patches.push({
|
|
7542
|
+
start: templateLoc.start,
|
|
7543
|
+
end: templateLoc.end,
|
|
7544
|
+
text: getValaxyDecryptTemplate({
|
|
7545
|
+
encryptedContent: "$encryptedContent",
|
|
7546
|
+
hint: frontmatter.password_hint
|
|
7547
|
+
})
|
|
7548
|
+
});
|
|
7549
|
+
} else {
|
|
7550
|
+
delete frontmatter.password;
|
|
7551
|
+
}
|
|
7552
|
+
if (scriptSetupLoc) {
|
|
7553
|
+
patches.push({
|
|
7554
|
+
start: scriptSetupLoc.start,
|
|
7555
|
+
end: scriptSetupLoc.end,
|
|
7556
|
+
text: ""
|
|
7557
|
+
});
|
|
7558
|
+
}
|
|
7559
|
+
for (const patch of patches.sort((a, b) => b.start - a.start))
|
|
7560
|
+
code = `${code.slice(0, patch.start)}${patch.text}${code.slice(patch.end)}`;
|
|
7010
7561
|
}
|
|
7011
7562
|
if (frontmatter.gallery_password) {
|
|
7012
7563
|
const encryptedPhotos = await encryptContent(JSON.stringify(frontmatter.photos), {
|
|
@@ -7548,11 +8099,25 @@ const templateConfig = {
|
|
|
7548
8099
|
redirect: redirect.to
|
|
7549
8100
|
};
|
|
7550
8101
|
});
|
|
7551
|
-
|
|
8102
|
+
const redirects = {
|
|
7552
8103
|
useVueRouter: isProd() ? options.config.siteConfig.redirects.useVueRouter : true,
|
|
7553
8104
|
redirectRoutes: routes
|
|
7554
8105
|
};
|
|
7555
|
-
|
|
8106
|
+
const { devtools, siteConfig, theme, themeConfig, runtimeConfig } = options.config;
|
|
8107
|
+
const config = options.mode === "dev" ? { ...options.config, runtimeConfig: { ...runtimeConfig, redirects } } : {
|
|
8108
|
+
devtools,
|
|
8109
|
+
siteConfig,
|
|
8110
|
+
theme,
|
|
8111
|
+
themeConfig,
|
|
8112
|
+
runtimeConfig: {
|
|
8113
|
+
redirects,
|
|
8114
|
+
addons: Object.fromEntries(Object.entries(runtimeConfig.addons).map(([key, addon]) => {
|
|
8115
|
+
const { name, enable, global, props, options: options2 } = addon;
|
|
8116
|
+
return [key, { name, enable, global, props, options: options2 }];
|
|
8117
|
+
}))
|
|
8118
|
+
}
|
|
8119
|
+
};
|
|
8120
|
+
return `export default ${JSON.stringify(JSON.stringify(config))}`;
|
|
7556
8121
|
}
|
|
7557
8122
|
};
|
|
7558
8123
|
|
|
@@ -7571,14 +8136,15 @@ const templateLocales = {
|
|
|
7571
8136
|
})
|
|
7572
8137
|
`
|
|
7573
8138
|
];
|
|
7574
|
-
const languages = config.siteConfig.languages || ["zh-CN", "en"];
|
|
8139
|
+
const languages = [...new Set(config.siteConfig.languages || ["zh-CN", "en"])];
|
|
7575
8140
|
roots.forEach((root, i) => {
|
|
7576
|
-
languages.forEach((lang) => {
|
|
8141
|
+
languages.forEach((lang, langIndex) => {
|
|
7577
8142
|
const langYml = `${root}/locales/${lang}.yml`;
|
|
7578
8143
|
if (fs.existsSync(langYml) && fs.readFileSync(langYml, "utf-8")) {
|
|
7579
|
-
const varName =
|
|
8144
|
+
const varName = `locale_${i}_${langIndex}`;
|
|
8145
|
+
const langKey = JSON.stringify(lang);
|
|
7580
8146
|
imports.unshift(`import ${varName} from "${toAtFS(langYml)}"`);
|
|
7581
|
-
imports.push(`messages[
|
|
8147
|
+
imports.push(`messages[${langKey}] = replaceArrMerge(${varName}, messages[${langKey}])`);
|
|
7582
8148
|
}
|
|
7583
8149
|
});
|
|
7584
8150
|
});
|
|
@@ -7676,8 +8242,7 @@ async function createValaxyPlugin(options, serverOptions = {}, state = Valaxy.st
|
|
|
7676
8242
|
}
|
|
7677
8243
|
if (id === "/@valaxyjs/context") {
|
|
7678
8244
|
return `export default ${JSON.stringify(JSON.stringify({
|
|
7679
|
-
userRoot: options.userRoot
|
|
7680
|
-
// clientRoot: options.clientRoot,
|
|
8245
|
+
userRoot: options.mode === "dev" ? options.userRoot : ""
|
|
7681
8246
|
}))}`;
|
|
7682
8247
|
}
|
|
7683
8248
|
if (id === "/@valaxyjs/AppVue")
|
|
@@ -7746,6 +8311,7 @@ async function createValaxyPlugin(options, serverOptions = {}, state = Valaxy.st
|
|
|
7746
8311
|
return reloadConfigAndEntries(valaxyConfig);
|
|
7747
8312
|
}
|
|
7748
8313
|
if (file.endsWith(".md")) {
|
|
8314
|
+
clearGitTimestampCache(getGitTimestampCache(options), file);
|
|
7749
8315
|
const endCount = countPerformanceTime();
|
|
7750
8316
|
const content = await read();
|
|
7751
8317
|
const { code, pageData } = await markdownToVue(content, file);
|
|
@@ -7855,7 +8421,7 @@ function generateAutoExcerptMd(content, length) {
|
|
|
7855
8421
|
return "";
|
|
7856
8422
|
return cleaned.length > length ? `${cleaned.slice(0, length)}...` : cleaned;
|
|
7857
8423
|
}
|
|
7858
|
-
async function createRouterPlugin(valaxyApp, base, editorRoutes) {
|
|
8424
|
+
async function createRouterPlugin(valaxyApp, base, editorRoutes, excerptAssets) {
|
|
7859
8425
|
const options = await createRouterOptions(valaxyApp, base);
|
|
7860
8426
|
return VueRouter({
|
|
7861
8427
|
...options,
|
|
@@ -7870,12 +8436,14 @@ async function createRouterPlugin(valaxyApp, base, editorRoutes) {
|
|
|
7870
8436
|
async beforeWriteFiles(root) {
|
|
7871
8437
|
await options.beforeWriteFiles?.(root);
|
|
7872
8438
|
await editorRoutes?.update(root);
|
|
8439
|
+
excerptAssets?.setRoutes(root);
|
|
7873
8440
|
}
|
|
7874
8441
|
});
|
|
7875
8442
|
}
|
|
7876
8443
|
async function createRouterOptions(valaxyApp, base, parseMatter = (source) => matter(source, matterOptions), onDispose) {
|
|
7877
8444
|
const { options } = valaxyApp;
|
|
7878
8445
|
const { roots, config: valaxyConfig } = options;
|
|
8446
|
+
clearGitTimestampCache(getGitTimestampCache(options));
|
|
7879
8447
|
const mdIt = await createMarkdownRenderer(options, base, onDispose);
|
|
7880
8448
|
let _lastFrontmatterRef = valaxyConfig.siteConfig.frontmatter;
|
|
7881
8449
|
let _cachedFrontmatter = structuredClone(valaxyConfig.siteConfig.frontmatter);
|
|
@@ -7961,11 +8529,12 @@ async function createRouterOptions(valaxyApp, base, parseMatter = (source) => ma
|
|
|
7961
8529
|
delete mdFm.gallery_password;
|
|
7962
8530
|
delete mdFm.photos;
|
|
7963
8531
|
}
|
|
8532
|
+
const gitTimestampCache = options.mode === "build" ? getGitTimestampCache(options) : void 0;
|
|
7964
8533
|
if (!mdFm.date)
|
|
7965
|
-
mdFm.date = new Date(await getCreatedTime(path));
|
|
8534
|
+
mdFm.date = new Date(await getCreatedTime(path, gitTimestampCache));
|
|
7966
8535
|
if (lastUpdated) {
|
|
7967
8536
|
if (!mdFm.updated)
|
|
7968
|
-
mdFm.updated = new Date(await getUpdatedTime(path));
|
|
8537
|
+
mdFm.updated = new Date(await getUpdatedTime(path, gitTimestampCache));
|
|
7969
8538
|
}
|
|
7970
8539
|
if (mdFm.from) {
|
|
7971
8540
|
if (Array.isArray(mdFm.from)) {
|
|
@@ -8142,6 +8711,7 @@ function createMemoryReleasePlugin(state, releaseThreshold = 1) {
|
|
|
8142
8711
|
async function ViteValaxyPlugins(valaxyApp, serverOptions = {}, viteConfig = {}, expectedBuilds = 1) {
|
|
8143
8712
|
const { options } = valaxyApp;
|
|
8144
8713
|
const state = new StateManager();
|
|
8714
|
+
const excerptAssets = createExcerptAssets();
|
|
8145
8715
|
const editorRoutes = options.mode === "dev" ? new EditorRoutes() : void 0;
|
|
8146
8716
|
const { roots, config: valaxyConfig } = options;
|
|
8147
8717
|
const markdownBase = createMarkdownBaseContext(viteConfig.base || valaxyConfig.vite?.base || "/");
|
|
@@ -8221,7 +8791,7 @@ async function ViteValaxyPlugins(valaxyApp, serverOptions = {}, viteConfig = {},
|
|
|
8221
8791
|
vLogger.debug(` \u251C\u2500 plugin-vue: ${timers.vue()}`);
|
|
8222
8792
|
return r;
|
|
8223
8793
|
}),
|
|
8224
|
-
createRouterPlugin(valaxyApp, markdownBase, editorRoutes).then((r) => {
|
|
8794
|
+
createRouterPlugin(valaxyApp, markdownBase, editorRoutes, excerptAssets).then((r) => {
|
|
8225
8795
|
vLogger.debug(` \u251C\u2500 createRouterPlugin: ${timers.router()}`);
|
|
8226
8796
|
return r;
|
|
8227
8797
|
}),
|
|
@@ -8244,6 +8814,7 @@ async function ViteValaxyPlugins(valaxyApp, serverOptions = {}, viteConfig = {},
|
|
|
8244
8814
|
...editorRoutes ? [editorPlugin(options, editorRoutes)] : [],
|
|
8245
8815
|
createCdnPlugin(options),
|
|
8246
8816
|
createLlmsPlugin(options),
|
|
8817
|
+
valaxyConfig.modules?.rss?.extractImagePathsFromHTML && createRssAssetsPlugin(options),
|
|
8247
8818
|
MarkdownPlugin,
|
|
8248
8819
|
ValaxyPlugin,
|
|
8249
8820
|
vuePlugin,
|
|
@@ -8253,6 +8824,7 @@ async function ViteValaxyPlugins(valaxyApp, serverOptions = {}, viteConfig = {},
|
|
|
8253
8824
|
Unhead(),
|
|
8254
8825
|
// https://router.vuejs.org/file-based-routing/
|
|
8255
8826
|
RouterPlugin,
|
|
8827
|
+
excerptAssets.plugin,
|
|
8256
8828
|
createLayoutsPlugin(options),
|
|
8257
8829
|
// https://github.com/antfu/unplugin-vue-components
|
|
8258
8830
|
Components({
|
|
@@ -8354,13 +8926,13 @@ async function renderPage(opts) {
|
|
|
8354
8926
|
const stateScript = serializeState(result.initialState);
|
|
8355
8927
|
let html = template;
|
|
8356
8928
|
if (headPayload.htmlAttrs)
|
|
8357
|
-
html = html.replace(/<html[^>]*>/, `<html ${headPayload.htmlAttrs}>`);
|
|
8929
|
+
html = html.replace(/<html[^>]*>/, () => `<html ${headPayload.htmlAttrs}>`);
|
|
8358
8930
|
if (headPayload.bodyAttrs)
|
|
8359
|
-
html = html.replace(/<body[^>]*>/, `<body ${headPayload.bodyAttrs}>`);
|
|
8360
|
-
html = html.replace("</head>", `${preloadLinks}${headPayload.headTags}
|
|
8931
|
+
html = html.replace(/<body[^>]*>/, () => `<body ${headPayload.bodyAttrs}>`);
|
|
8932
|
+
html = html.replace("</head>", () => `${preloadLinks}${headPayload.headTags}
|
|
8361
8933
|
</head>`).replace(
|
|
8362
8934
|
'<div id="app"></div>',
|
|
8363
|
-
`${headPayload.bodyTagsOpen || ""}<div id="app">${result.html}</div>${stateScript}${headPayload.bodyTags || ""}`
|
|
8935
|
+
() => `${headPayload.bodyTagsOpen || ""}<div id="app">${result.html}</div>${stateScript}${headPayload.bodyTags || ""}`
|
|
8364
8936
|
);
|
|
8365
8937
|
if (result.teleports) {
|
|
8366
8938
|
for (const [target, content] of Object.entries(result.teleports)) {
|
|
@@ -8370,12 +8942,12 @@ async function renderPage(opts) {
|
|
|
8370
8942
|
throw new Error("Missing #valaxy-teleports container in the HTML template");
|
|
8371
8943
|
html = html.replace(container, () => `<div id="valaxy-teleports">${content}</div>`);
|
|
8372
8944
|
} else if (target === "head") {
|
|
8373
|
-
html = html.replace("</head>", `${content}
|
|
8945
|
+
html = html.replace("</head>", () => `${content}
|
|
8374
8946
|
</head>`);
|
|
8375
8947
|
} else if (target === "body") {
|
|
8376
8948
|
html = html.replace(/<body\b[^>]*>/, (match) => `${match}${content}`);
|
|
8377
8949
|
} else {
|
|
8378
|
-
html = html.replace("</body>", `${content}
|
|
8950
|
+
html = html.replace("</body>", () => `${content}
|
|
8379
8951
|
</body>`);
|
|
8380
8952
|
}
|
|
8381
8953
|
}
|
|
@@ -8387,6 +8959,41 @@ async function renderPage(opts) {
|
|
|
8387
8959
|
const filePath = resolve(opts.outDir, fileName);
|
|
8388
8960
|
await mkdir(dirname(filePath), { recursive: true });
|
|
8389
8961
|
await writeFile(filePath, html, "utf-8");
|
|
8962
|
+
return { route: opts.route, ...readCanonicalLink(html) };
|
|
8963
|
+
}
|
|
8964
|
+
function readCanonicalLink(html) {
|
|
8965
|
+
let canonical;
|
|
8966
|
+
let baseHref;
|
|
8967
|
+
let inHead = false;
|
|
8968
|
+
let templateDepth = 0;
|
|
8969
|
+
const parser = new Parser({
|
|
8970
|
+
onopentag(tag, attrs) {
|
|
8971
|
+
if (tag === "body") {
|
|
8972
|
+
parser.pause();
|
|
8973
|
+
return;
|
|
8974
|
+
}
|
|
8975
|
+
if (tag === "head")
|
|
8976
|
+
inHead = true;
|
|
8977
|
+
if (!inHead)
|
|
8978
|
+
return;
|
|
8979
|
+
if (tag === "template")
|
|
8980
|
+
templateDepth++;
|
|
8981
|
+
if (templateDepth)
|
|
8982
|
+
return;
|
|
8983
|
+
if (tag === "base")
|
|
8984
|
+
baseHref ??= attrs.href;
|
|
8985
|
+
if (tag === "link" && attrs.rel?.toLowerCase().split(/\s+/).includes("canonical"))
|
|
8986
|
+
canonical ??= attrs.href;
|
|
8987
|
+
},
|
|
8988
|
+
onclosetag(tag) {
|
|
8989
|
+
if (tag === "template" && templateDepth)
|
|
8990
|
+
templateDepth--;
|
|
8991
|
+
if (tag === "head")
|
|
8992
|
+
parser.pause();
|
|
8993
|
+
}
|
|
8994
|
+
});
|
|
8995
|
+
parser.end(html);
|
|
8996
|
+
return { canonical, baseHref };
|
|
8390
8997
|
}
|
|
8391
8998
|
function renderPreloadLinks(modules, manifest) {
|
|
8392
8999
|
if (!modules || modules.size === 0)
|
|
@@ -8420,7 +9027,7 @@ function renderPreloadLinks(modules, manifest) {
|
|
|
8420
9027
|
function serializeState(state) {
|
|
8421
9028
|
if (!state || Object.keys(state).length === 0)
|
|
8422
9029
|
return "";
|
|
8423
|
-
const serialised = JSON.stringify(state).replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026").replace(/'/g, "\\u0027").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
9030
|
+
const serialised = JSON.stringify(state).replace(/\\/g, "\\\\").replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026").replace(/'/g, "\\u0027").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
8424
9031
|
return `<script>window.__INITIAL_STATE__='${serialised}'<\/script>`;
|
|
8425
9032
|
}
|
|
8426
9033
|
function decodePathSegment(segment) {
|
|
@@ -8439,7 +9046,7 @@ function routeToFileName(route) {
|
|
|
8439
9046
|
return `${route}.html`.slice(1);
|
|
8440
9047
|
}
|
|
8441
9048
|
function trailingSlashAlias(route) {
|
|
8442
|
-
if (!route || route
|
|
9049
|
+
if (!route || route.endsWith("/") || isNotFoundPagePath(route))
|
|
8443
9050
|
return;
|
|
8444
9051
|
const file = routeToFileName(route);
|
|
8445
9052
|
if (!file.endsWith(".html") || file.endsWith("/index.html"))
|
|
@@ -8456,7 +9063,7 @@ async function fileExists(file) {
|
|
|
8456
9063
|
}
|
|
8457
9064
|
async function writeTrailingSlashAliases(outDir, routes) {
|
|
8458
9065
|
const outputs = new Set(routes.map(routeToFileName));
|
|
8459
|
-
await
|
|
9066
|
+
await pMap(routes, async (route) => {
|
|
8460
9067
|
const alias = trailingSlashAlias(route);
|
|
8461
9068
|
if (!alias || outputs.has(alias))
|
|
8462
9069
|
return;
|
|
@@ -8466,7 +9073,56 @@ async function writeTrailingSlashAliases(outDir, routes) {
|
|
|
8466
9073
|
return;
|
|
8467
9074
|
await mkdir(dirname(to), { recursive: true });
|
|
8468
9075
|
await copyFile(from, to);
|
|
8469
|
-
})
|
|
9076
|
+
}, { concurrency: 32 });
|
|
9077
|
+
}
|
|
9078
|
+
|
|
9079
|
+
async function writeSitemap(outDir, siteUrl, pages) {
|
|
9080
|
+
if (!/^https?:\/\//i.test(siteUrl))
|
|
9081
|
+
return;
|
|
9082
|
+
const base = new URL(siteUrl);
|
|
9083
|
+
base.pathname = `${base.pathname.replace(/\/+$/, "")}/`;
|
|
9084
|
+
base.search = "";
|
|
9085
|
+
base.hash = "";
|
|
9086
|
+
const urls = /* @__PURE__ */ new Set();
|
|
9087
|
+
const routesWithCanonical = /* @__PURE__ */ new Set();
|
|
9088
|
+
const fallbacks = /* @__PURE__ */ new Map();
|
|
9089
|
+
for (const { route, canonical, baseHref } of pages) {
|
|
9090
|
+
const routeUrl = new URL(`.${route}`, base);
|
|
9091
|
+
if (isNotFoundPagePath(routeUrl.pathname))
|
|
9092
|
+
continue;
|
|
9093
|
+
const key = routeUrl.href.replace(/\/$/, "");
|
|
9094
|
+
if (canonical !== void 0) {
|
|
9095
|
+
routesWithCanonical.add(key);
|
|
9096
|
+
const documentBase = baseHref ? URL.parse(baseHref, routeUrl) ?? routeUrl : routeUrl;
|
|
9097
|
+
const url = canonical.trim() ? URL.parse(canonical, documentBase) : null;
|
|
9098
|
+
if (url?.origin === base.origin && url.pathname.startsWith(base.pathname) && !isNotFoundPagePath(url.pathname))
|
|
9099
|
+
urls.add(url.href);
|
|
9100
|
+
} else if (!fallbacks.has(key) || routeUrl.pathname.endsWith("/")) {
|
|
9101
|
+
fallbacks.set(key, routeUrl.href);
|
|
9102
|
+
}
|
|
9103
|
+
}
|
|
9104
|
+
for (const [key, url] of fallbacks) {
|
|
9105
|
+
if (!routesWithCanonical.has(key))
|
|
9106
|
+
urls.add(url);
|
|
9107
|
+
}
|
|
9108
|
+
const sitemap = [
|
|
9109
|
+
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
9110
|
+
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
|
|
9111
|
+
...[...urls].sort().map((url) => ` <url><loc>${escapeHtml$1(url)}</loc></url>`),
|
|
9112
|
+
"</urlset>",
|
|
9113
|
+
""
|
|
9114
|
+
].join("\n");
|
|
9115
|
+
await Promise.all([
|
|
9116
|
+
writeFile(join(outDir, "sitemap.xml"), sitemap),
|
|
9117
|
+
writeFile(join(outDir, "robots.txt"), `User-agent: *
|
|
9118
|
+
Allow: /
|
|
9119
|
+
|
|
9120
|
+
Sitemap: ${new URL("sitemap.xml", base).href}
|
|
9121
|
+
`, { flag: "wx" }).catch((error) => {
|
|
9122
|
+
if (error.code !== "EEXIST")
|
|
9123
|
+
throw error;
|
|
9124
|
+
})
|
|
9125
|
+
]);
|
|
8470
9126
|
}
|
|
8471
9127
|
|
|
8472
9128
|
function tryGC() {
|
|
@@ -8500,13 +9156,20 @@ function getSsgSsrConfig() {
|
|
|
8500
9156
|
}
|
|
8501
9157
|
async function ssgBuild(valaxyApp, viteConfig = {}, userSsgOptions = {}) {
|
|
8502
9158
|
const { options } = valaxyApp;
|
|
8503
|
-
const
|
|
8504
|
-
|
|
9159
|
+
const { viteConfig: effectiveClientViteConfig, outDir } = await resolveEffectiveViteConfig(
|
|
9160
|
+
options,
|
|
9161
|
+
"build",
|
|
9162
|
+
viteConfig,
|
|
9163
|
+
void 0,
|
|
9164
|
+
false
|
|
9165
|
+
);
|
|
9166
|
+
delete effectiveClientViteConfig.ssgOptions;
|
|
8505
9167
|
const ssgTemp = resolve(outDir, ".vite-ssg-temp");
|
|
8506
9168
|
let routePaths = [];
|
|
9169
|
+
let renderedPages;
|
|
8507
9170
|
const defaultConfig = {
|
|
8508
9171
|
...defaultViteConfig,
|
|
8509
|
-
plugins: await profileBuildPhase("plugins", () => ViteValaxyPlugins(valaxyApp, {},
|
|
9172
|
+
plugins: await profileBuildPhase("plugins", () => ViteValaxyPlugins(valaxyApp, {}, effectiveClientViteConfig, 2)),
|
|
8510
9173
|
// `ssr.noExternal` only affects the server build (step 2) — the client build
|
|
8511
9174
|
// ignores it. See `getSsgSsrConfig` for why everything is bundled.
|
|
8512
9175
|
ssr: getSsgSsrConfig(),
|
|
@@ -8517,17 +9180,26 @@ async function ssgBuild(valaxyApp, viteConfig = {}, userSsgOptions = {}) {
|
|
|
8517
9180
|
watch: null
|
|
8518
9181
|
}
|
|
8519
9182
|
};
|
|
8520
|
-
const
|
|
9183
|
+
const clientInlineConfig = mergeConfig(defaultConfig, effectiveClientViteConfig);
|
|
8521
9184
|
try {
|
|
8522
9185
|
consola.info("Building client bundle...");
|
|
8523
|
-
await profileBuildPhase("client-bundle", () => build$3(mergeConfig(
|
|
9186
|
+
await profileBuildPhase("client-bundle", () => build$3(mergeConfig(clientInlineConfig, {
|
|
8524
9187
|
build: {
|
|
8525
9188
|
ssrManifest: true,
|
|
8526
9189
|
outDir
|
|
8527
9190
|
}
|
|
8528
9191
|
})));
|
|
9192
|
+
const { viteConfig: effectiveServerViteConfig } = await resolveEffectiveViteConfig(
|
|
9193
|
+
options,
|
|
9194
|
+
"build",
|
|
9195
|
+
viteConfig,
|
|
9196
|
+
void 0,
|
|
9197
|
+
true
|
|
9198
|
+
);
|
|
9199
|
+
delete effectiveServerViteConfig.ssgOptions;
|
|
9200
|
+
const serverInlineConfig = mergeConfig(defaultConfig, effectiveServerViteConfig);
|
|
8529
9201
|
consola.info("Building server bundle...");
|
|
8530
|
-
await profileBuildPhase("server-bundle", () => build$3(mergeConfig(
|
|
9202
|
+
await profileBuildPhase("server-bundle", () => build$3(mergeConfig(serverInlineConfig, {
|
|
8531
9203
|
build: {
|
|
8532
9204
|
ssr: resolve(options.clientRoot, "entry-ssr.ts"),
|
|
8533
9205
|
outDir: ssgTemp,
|
|
@@ -8566,7 +9238,7 @@ async function ssgBuild(valaxyApp, viteConfig = {}, userSsgOptions = {}) {
|
|
|
8566
9238
|
);
|
|
8567
9239
|
const concurrency = userSsgOptions.concurrency ?? 20;
|
|
8568
9240
|
consola.info(`Rendering ${colors.yellow(routePaths.length)} pages (concurrency: ${colors.yellow(concurrency)})...`);
|
|
8569
|
-
await profileBuildPhase("render-pages", () => pMap(
|
|
9241
|
+
renderedPages = await profileBuildPhase("render-pages", () => pMap(
|
|
8570
9242
|
routePaths,
|
|
8571
9243
|
(route) => renderPage({
|
|
8572
9244
|
render,
|
|
@@ -8586,21 +9258,24 @@ async function ssgBuild(valaxyApp, viteConfig = {}, userSsgOptions = {}) {
|
|
|
8586
9258
|
await rm(resolve(outDir, ".vite"), { recursive: true, force: true }).catch(() => {
|
|
8587
9259
|
});
|
|
8588
9260
|
}
|
|
8589
|
-
|
|
8590
|
-
hostname: options.config.siteConfig.url,
|
|
8591
|
-
outDir,
|
|
8592
|
-
exclude: notFoundSitemapPaths(routePaths)
|
|
8593
|
-
});
|
|
9261
|
+
await writeSitemap(outDir, options.config.siteConfig.url, renderedPages);
|
|
8594
9262
|
await writeTrailingSlashAliases(outDir, routePaths);
|
|
8595
9263
|
if (userSsgOptions.onFinished)
|
|
8596
9264
|
await userSsgOptions.onFinished();
|
|
8597
9265
|
}
|
|
8598
9266
|
|
|
8599
9267
|
async function build(valaxyApp, viteConfig = defaultViteConfig) {
|
|
8600
|
-
const
|
|
8601
|
-
|
|
8602
|
-
|
|
8603
|
-
|
|
9268
|
+
const { viteConfig: resolvedViteConfig } = await resolveEffectiveViteConfig(
|
|
9269
|
+
valaxyApp.options,
|
|
9270
|
+
"build",
|
|
9271
|
+
viteConfig,
|
|
9272
|
+
void 0,
|
|
9273
|
+
false
|
|
9274
|
+
);
|
|
9275
|
+
const inlineConfig = mergeConfig(
|
|
9276
|
+
mergeConfig(defaultViteConfig, resolvedViteConfig),
|
|
9277
|
+
{ plugins: await ViteValaxyPlugins(valaxyApp, {}, resolvedViteConfig) }
|
|
9278
|
+
);
|
|
8604
9279
|
await build$3(inlineConfig);
|
|
8605
9280
|
}
|
|
8606
9281
|
async function postProcessForSSG(options) {
|
|
@@ -8609,7 +9284,7 @@ async function postProcessForSSG(options) {
|
|
|
8609
9284
|
}
|
|
8610
9285
|
async function generateClientRedirects(options) {
|
|
8611
9286
|
consola.info("generate client redirects...");
|
|
8612
|
-
const outputPath =
|
|
9287
|
+
const { outDir: outputPath } = resolveBuildPaths(options);
|
|
8613
9288
|
const redirectRules = collectRedirects(options.redirects);
|
|
8614
9289
|
const task = redirectRules.map(async (rule) => {
|
|
8615
9290
|
const fromPath = join(outputPath, `${rule.from}.html`);
|
|
@@ -9116,21 +9791,22 @@ async function execBuild({ ssg, root, output, log, siteUrl }) {
|
|
|
9116
9791
|
valaxyApp,
|
|
9117
9792
|
modules
|
|
9118
9793
|
);
|
|
9119
|
-
const valaxyViteConfig = mergeConfig(await mergeViteConfigs(options, "build"), options.config.vite || {});
|
|
9120
|
-
const viteConfig = mergeConfig(
|
|
9121
|
-
valaxyViteConfig,
|
|
9122
|
-
{
|
|
9123
|
-
// avoid load userRoot/vite.config.ts repeatedly
|
|
9124
|
-
configFile: path.resolve(options.clientRoot, "vite.config.ts"),
|
|
9125
|
-
build: {
|
|
9126
|
-
// make out dir empty, https://vitejs.dev/config/#build-emptyoutdir
|
|
9127
|
-
emptyOutDir: true,
|
|
9128
|
-
outDir: path.resolve(options.userRoot, output)
|
|
9129
|
-
},
|
|
9130
|
-
logLevel: log
|
|
9131
|
-
}
|
|
9132
|
-
);
|
|
9133
9794
|
await callHookWithLog("config:init", valaxyApp);
|
|
9795
|
+
const rawViteConfig = {
|
|
9796
|
+
build: {
|
|
9797
|
+
// make out dir empty, https://vitejs.dev/config/#build-emptyoutdir
|
|
9798
|
+
emptyOutDir: true,
|
|
9799
|
+
...output !== void 0 ? { outDir: path.resolve(options.userRoot, output) } : {}
|
|
9800
|
+
},
|
|
9801
|
+
logLevel: log
|
|
9802
|
+
};
|
|
9803
|
+
const { viteConfig } = await resolveEffectiveViteConfig(
|
|
9804
|
+
options,
|
|
9805
|
+
"build",
|
|
9806
|
+
rawViteConfig,
|
|
9807
|
+
output,
|
|
9808
|
+
false
|
|
9809
|
+
);
|
|
9134
9810
|
await profileBuildPhase("build-before", () => callHookWithLog("build:before", valaxyApp));
|
|
9135
9811
|
await validateTaxonomyI18n(options);
|
|
9136
9812
|
consola.box("\u{1F320} Start building...");
|
|
@@ -9161,7 +9837,6 @@ function registerBuildCommand(cli) {
|
|
|
9161
9837
|
}).option("output", {
|
|
9162
9838
|
alias: "o",
|
|
9163
9839
|
type: "string",
|
|
9164
|
-
default: "dist",
|
|
9165
9840
|
describe: "output dir"
|
|
9166
9841
|
}).option("log", {
|
|
9167
9842
|
default: "warn",
|
|
@@ -9292,6 +9967,7 @@ function createContentService(app, settings = {}) {
|
|
|
9292
9967
|
const options = await routerOptions;
|
|
9293
9968
|
const routes = [];
|
|
9294
9969
|
routerApp.options.redirects.length = 0;
|
|
9970
|
+
clearGitTimestampCache(getGitTimestampCache(routerApp.options));
|
|
9295
9971
|
const context = createRoutesContext(resolveOptions$3({
|
|
9296
9972
|
...options,
|
|
9297
9973
|
root: userRoot,
|
|
@@ -9419,6 +10095,16 @@ function createContentService(app, settings = {}) {
|
|
|
9419
10095
|
add("route-collision", "error", `The route or alias ${key} is used by multiple pages.`, "Choose a unique route path or alias in your route hooks.");
|
|
9420
10096
|
}
|
|
9421
10097
|
}
|
|
10098
|
+
const isPost = page.routes.some((route) => route.path.startsWith("/posts/") || route.layout === "post");
|
|
10099
|
+
if (isPost && !page.draft && (data.description === void 0 || typeof data.description === "string" && !data.description.trim())) {
|
|
10100
|
+
add(
|
|
10101
|
+
"missing-description",
|
|
10102
|
+
"warning",
|
|
10103
|
+
"Post is missing a frontmatter description.",
|
|
10104
|
+
"Add a concise description in frontmatter for SEO, RSS, and social sharing.",
|
|
10105
|
+
data.description !== void 0 ? fieldLine("description") : 1
|
|
10106
|
+
);
|
|
10107
|
+
}
|
|
9422
10108
|
try {
|
|
9423
10109
|
const layoutNames = await resolveContentLayouts(app.options);
|
|
9424
10110
|
for (const layout of new Set(page.routes.map((route) => route.layout))) {
|
|
@@ -10088,4 +10774,4 @@ async function run(argv = hideBin(process.argv), options = {}) {
|
|
|
10088
10774
|
await cli.parseAsync();
|
|
10089
10775
|
}
|
|
10090
10776
|
|
|
10091
|
-
export {
|
|
10777
|
+
export { resolveThemeValaxyConfig as $, ALL_ROUTE as A, getServerInfoText as B, isExternal as C, isInstalledGlobally as D, EXCERPT_SEPARATOR as E, isKatexEnabled as F, GLOBAL_STATE as G, isKatexPluginNeeded as H, isMathJaxEnabled as I, isPath as J, loadAllContent as K, loadConfigFromFile as L, mergeValaxyConfig as M, mergeViteConfigs as N, postProcessForSSG as O, PATHNAME_PROTOCOL_RE as P, processValaxyOptions as Q, registerDevCommand as R, StateManager as S, resolveAddonsConfig as T, resolveImportPath as U, ViteValaxyPlugins as V, resolveImportUrl as W, resolveOptions$2 as X, resolveSiteConfig as Y, resolveSiteConfigFromRoot as Z, resolveThemeConfigFromRoot as _, createCli as a, resolveUserThemeConfig as a0, resolveValaxyConfig as a1, resolveValaxyConfigFromRoot as a2, run as a3, ssgBuild as a4, startValaxyDev as a5, toAtFS as a6, transformObject as a7, version as a8, build as b, clearGitTimestampCache as c, createContentService as d, createMemoryReleasePlugin as e, createServer as f, createValaxyNode as g, createValaxyPlugin as h, customElements as i, defaultSiteConfig as j, defaultValaxyConfig as k, defaultViteConfig as l, defineAddon as m, defineConfig as n, defineSiteConfig as o, defineTheme as p, defineValaxyAddon as q, defineValaxyConfig as r, defineValaxyTheme as s, desktopRuntimeVersion as t, encryptContent as u, execBuild as v, generateClientRedirects as w, getGitTimestamp as x, getGitTimestampCache as y, getIndexHtml as z };
|