vitepress-allyouneed 0.1.0 → 0.2.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +400 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +400 -10
- package/dist/index.js.map +1 -1
- package/dist/markdown-it.cjs +29 -5
- package/dist/markdown-it.cjs.map +1 -1
- package/dist/markdown-it.d.cts +1 -1
- package/dist/markdown-it.d.ts +1 -1
- package/dist/markdown-it.js +29 -5
- package/dist/markdown-it.js.map +1 -1
- package/dist/theme/components/Tags.vue +157 -0
- package/dist/theme/components/VaultGraph.vue +317 -0
- package/dist/theme/components/VaultStats.vue +53 -0
- package/dist/theme/composables/useVaultData.cjs +73 -0
- package/dist/theme/composables/useVaultData.cjs.map +1 -0
- package/dist/theme/composables/useVaultData.d.cts +61 -0
- package/dist/theme/composables/useVaultData.d.ts +61 -0
- package/dist/theme/composables/useVaultData.js +48 -0
- package/dist/theme/composables/useVaultData.js.map +1 -0
- package/dist/theme/index.cjs +107 -0
- package/dist/theme/index.cjs.map +1 -0
- package/dist/theme/index.d.cts +62 -0
- package/dist/theme/index.d.ts +62 -0
- package/dist/theme/index.js +69 -0
- package/dist/theme/index.js.map +1 -0
- package/dist/theme/styles/graph.css +79 -0
- package/dist/theme/styles/index.css +6 -0
- package/dist/theme/styles/shared.css +71 -0
- package/dist/theme/styles/stats.css +77 -0
- package/dist/theme/styles/tags.css +308 -0
- package/dist/{types-CapUIPbW.d.cts → types-DDe7q023.d.cts} +63 -0
- package/dist/{types-CapUIPbW.d.ts → types-DDe7q023.d.ts} +63 -0
- package/dist/vite.cjs +293 -6
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.d.cts +1 -1
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +293 -6
- package/dist/vite.js.map +1 -1
- package/dist/vitepress.cjs +400 -10
- package/dist/vitepress.cjs.map +1 -1
- package/dist/vitepress.d.cts +1 -1
- package/dist/vitepress.d.ts +1 -1
- package/dist/vitepress.js +400 -10
- package/dist/vitepress.js.map +1 -1
- package/package.json +24 -5
- package/style.css +34 -21
package/dist/index.cjs
CHANGED
|
@@ -113,6 +113,7 @@ function resolveOptions(user = {}, ctx = {}) {
|
|
|
113
113
|
const scanUser = user.scan ?? {};
|
|
114
114
|
const assetsUser = user.assets ?? {};
|
|
115
115
|
const modulesUser = user.modules ?? {};
|
|
116
|
+
const viewsUser = user.views ?? {};
|
|
116
117
|
const wikilinksHtmlAttrs = wikilinksUser.htmlAttributes ?? {};
|
|
117
118
|
const embedsHtmlAttrs = embedsUser.htmlAttributes ?? {};
|
|
118
119
|
return {
|
|
@@ -151,9 +152,33 @@ function resolveOptions(user = {}, ctx = {}) {
|
|
|
151
152
|
transclusionMaxDepth: embedsUser.transclusionMaxDepth ?? 8,
|
|
152
153
|
htmlAttributes: embedsHtmlAttrs
|
|
153
154
|
},
|
|
155
|
+
views: {
|
|
156
|
+
enabled: {
|
|
157
|
+
graph: viewsUser.enabled?.graph ?? true,
|
|
158
|
+
stats: viewsUser.enabled?.stats ?? true,
|
|
159
|
+
tags: viewsUser.enabled?.tags ?? true
|
|
160
|
+
},
|
|
161
|
+
urlPrefix: viewsUser.urlPrefix ?? "_perspectives_",
|
|
162
|
+
names: {
|
|
163
|
+
graph: viewsUser.names?.graph ?? "graph",
|
|
164
|
+
stats: viewsUser.names?.stats ?? "stats",
|
|
165
|
+
tags: viewsUser.names?.tags ?? "tags"
|
|
166
|
+
},
|
|
167
|
+
sidebar: viewsUser.sidebar ?? "auto",
|
|
168
|
+
sidebarText: {
|
|
169
|
+
group: viewsUser.sidebarText?.group ?? "Perspectives",
|
|
170
|
+
graph: viewsUser.sidebarText?.graph ?? "Graph",
|
|
171
|
+
stats: viewsUser.sidebarText?.stats ?? "Stats",
|
|
172
|
+
tags: viewsUser.sidebarText?.tags ?? "Tags"
|
|
173
|
+
},
|
|
174
|
+
graphMaxNodes: viewsUser.graphMaxNodes ?? 500,
|
|
175
|
+
dataFileName: viewsUser.dataFileName ?? "vault-data.json",
|
|
176
|
+
parseInlineTags: viewsUser.parseInlineTags ?? true
|
|
177
|
+
},
|
|
154
178
|
modules: {
|
|
155
179
|
wikilinks: modulesUser.wikilinks ?? true,
|
|
156
|
-
embeds: modulesUser.embeds ?? true
|
|
180
|
+
embeds: modulesUser.embeds ?? true,
|
|
181
|
+
views: modulesUser.views ?? true
|
|
157
182
|
},
|
|
158
183
|
slugify
|
|
159
184
|
};
|
|
@@ -1005,11 +1030,10 @@ function renderTransclusionHtml(md, rawTarget, aliasParts, env) {
|
|
|
1005
1030
|
inner = md.render(fragment, childEnv);
|
|
1006
1031
|
cache.set(cacheKey, { html: inner });
|
|
1007
1032
|
}
|
|
1008
|
-
const sourceUrl = headingPart ? `${target.url}#${
|
|
1033
|
+
const sourceUrl = headingPart ? `${target.url}#${options.slugify(headingPart)}` : target.url;
|
|
1009
1034
|
const aliasData = aliasParts.length ? ` data-caption="${escapeHtml(aliasParts.join("|"))}"` : "";
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
)}" data-source-url="${escapeHtml(sourceUrl)}"${aliasData}>${inner}</div>`;
|
|
1035
|
+
const sourceLink = `<a class="transclusion-source-link" href="${escapeHtml(sourceUrl)}" aria-label="Go to source: ${escapeHtml(target.relativePath)}" title="${escapeHtml(target.relativePath)}">\u2197</a>`;
|
|
1036
|
+
return `<div class="transclusion" data-source="${escapeHtml(target.relativePath)}" data-source-url="${escapeHtml(sourceUrl)}"${aliasData}>` + sourceLink + inner + `</div>`;
|
|
1013
1037
|
}
|
|
1014
1038
|
function handleTransclusion(state, rawTarget, aliasParts, env) {
|
|
1015
1039
|
if (env.options.deadLink !== "silent") {
|
|
@@ -1227,8 +1251,8 @@ function isResolved(o) {
|
|
|
1227
1251
|
var markdown_it_default = allYouNeedMarkdownIt;
|
|
1228
1252
|
|
|
1229
1253
|
// src/vite.ts
|
|
1230
|
-
var
|
|
1231
|
-
var
|
|
1254
|
+
var import_node_fs7 = __toESM(require("fs"), 1);
|
|
1255
|
+
var import_node_path8 = __toESM(require("path"), 1);
|
|
1232
1256
|
|
|
1233
1257
|
// src/core/asset-pipeline/dev-middleware.ts
|
|
1234
1258
|
var import_node_fs4 = __toESM(require("fs"), 1);
|
|
@@ -1298,6 +1322,235 @@ function guessMime(ext) {
|
|
|
1298
1322
|
return MIME[ext.toLowerCase()] ?? "application/octet-stream";
|
|
1299
1323
|
}
|
|
1300
1324
|
|
|
1325
|
+
// src/core/views/generate-md.ts
|
|
1326
|
+
var import_node_fs5 = __toESM(require("fs"), 1);
|
|
1327
|
+
var import_node_path6 = __toESM(require("path"), 1);
|
|
1328
|
+
var VIEW_SENTINEL = "<!-- generated by vitepress-allyouneed (do not edit; will be regenerated) -->";
|
|
1329
|
+
function generateViewMarkdown(options, index) {
|
|
1330
|
+
const report = { written: [], skipped: [] };
|
|
1331
|
+
if (!options.modules.views) return report;
|
|
1332
|
+
const srcDir = import_node_path6.default.resolve(options.srcDir);
|
|
1333
|
+
const prefix = options.views.urlPrefix;
|
|
1334
|
+
const viewDir = prefix ? import_node_path6.default.join(srcDir, prefix) : srcDir;
|
|
1335
|
+
if (prefix) {
|
|
1336
|
+
try {
|
|
1337
|
+
import_node_fs5.default.mkdirSync(viewDir, { recursive: true });
|
|
1338
|
+
} catch {
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
const views = buildViewList(options);
|
|
1342
|
+
for (const v of views) {
|
|
1343
|
+
const target = import_node_path6.default.join(viewDir, v.fileName);
|
|
1344
|
+
if (import_node_fs5.default.existsSync(target)) {
|
|
1345
|
+
let existing;
|
|
1346
|
+
try {
|
|
1347
|
+
existing = import_node_fs5.default.readFileSync(target, "utf8");
|
|
1348
|
+
} catch {
|
|
1349
|
+
report.skipped.push({ path: target, reason: "\u6587\u4EF6\u4E0D\u53EF\u8BFB,\u8DF3\u8FC7" });
|
|
1350
|
+
continue;
|
|
1351
|
+
}
|
|
1352
|
+
if (!existing.includes(VIEW_SENTINEL)) {
|
|
1353
|
+
report.skipped.push({
|
|
1354
|
+
path: target,
|
|
1355
|
+
reason: `\u7528\u6237\u5DF2\u6709\u540C\u540D\u6587\u4EF6,\u4E0D\u8986\u76D6\u3002\u8981\u542F\u7528\u6B64\u89C6\u56FE\u8BF7:(a) \u5220\u9664\u8BE5\u6587\u4EF6 / (b) views.names.${v.kind} \u6539\u540D / (c) views.enabled.${v.kind}: false \u5173\u6389`
|
|
1356
|
+
});
|
|
1357
|
+
continue;
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
try {
|
|
1361
|
+
import_node_fs5.default.writeFileSync(target, renderTemplate(v), "utf8");
|
|
1362
|
+
report.written.push(target);
|
|
1363
|
+
void index;
|
|
1364
|
+
} catch (err) {
|
|
1365
|
+
report.skipped.push({
|
|
1366
|
+
path: target,
|
|
1367
|
+
reason: `\u5199\u5165\u5931\u8D25: ${err instanceof Error ? err.message : String(err)}`
|
|
1368
|
+
});
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
return report;
|
|
1372
|
+
}
|
|
1373
|
+
function buildViewList(options) {
|
|
1374
|
+
const { enabled, names, sidebarText, graphMaxNodes } = options.views;
|
|
1375
|
+
const list = [];
|
|
1376
|
+
if (enabled.graph) {
|
|
1377
|
+
list.push({
|
|
1378
|
+
kind: "graph",
|
|
1379
|
+
fileName: `${names.graph}.md`,
|
|
1380
|
+
title: sidebarText.graph,
|
|
1381
|
+
// 把配置里的 graphMaxNodes 直接注入到组件 prop
|
|
1382
|
+
component: `<VaultGraph :max-nodes="${graphMaxNodes}" />`
|
|
1383
|
+
});
|
|
1384
|
+
}
|
|
1385
|
+
if (enabled.stats) {
|
|
1386
|
+
list.push({
|
|
1387
|
+
kind: "stats",
|
|
1388
|
+
fileName: `${names.stats}.md`,
|
|
1389
|
+
title: sidebarText.stats,
|
|
1390
|
+
component: "<VaultStats />"
|
|
1391
|
+
});
|
|
1392
|
+
}
|
|
1393
|
+
if (enabled.tags) {
|
|
1394
|
+
list.push({
|
|
1395
|
+
kind: "tags",
|
|
1396
|
+
fileName: `${names.tags}.md`,
|
|
1397
|
+
title: sidebarText.tags,
|
|
1398
|
+
component: "<Tags />"
|
|
1399
|
+
});
|
|
1400
|
+
}
|
|
1401
|
+
return list;
|
|
1402
|
+
}
|
|
1403
|
+
function renderTemplate(v) {
|
|
1404
|
+
return [
|
|
1405
|
+
"---",
|
|
1406
|
+
`title: ${v.title}`,
|
|
1407
|
+
"layout: doc",
|
|
1408
|
+
"aside: false",
|
|
1409
|
+
"outline: false",
|
|
1410
|
+
"---",
|
|
1411
|
+
"",
|
|
1412
|
+
VIEW_SENTINEL,
|
|
1413
|
+
"",
|
|
1414
|
+
`# ${v.title}`,
|
|
1415
|
+
"",
|
|
1416
|
+
v.component,
|
|
1417
|
+
""
|
|
1418
|
+
].join("\n");
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1421
|
+
// src/core/views/generate-data.ts
|
|
1422
|
+
var import_node_fs6 = __toESM(require("fs"), 1);
|
|
1423
|
+
var import_node_path7 = __toESM(require("path"), 1);
|
|
1424
|
+
var PLUGIN_VERSION = "0.2.0-beta.0";
|
|
1425
|
+
var WIKILINK_RE = /(!?)\[\[([^\]\n|#]+)(?:#[^\]\n|]*)?(?:\|[^\]\n]*)?\]\]/g;
|
|
1426
|
+
var BODY_TAG_RE = /(?:^|[\s([{,;。,;])#([\p{L}_][\p{L}\p{N}_/-]*)/gu;
|
|
1427
|
+
function buildVaultData(index, options) {
|
|
1428
|
+
const nodes = [];
|
|
1429
|
+
for (const f of index.files.values()) {
|
|
1430
|
+
nodes.push({
|
|
1431
|
+
id: f.relativePath,
|
|
1432
|
+
title: pickTitle(f),
|
|
1433
|
+
url: f.url,
|
|
1434
|
+
tags: [...f.tags],
|
|
1435
|
+
mtime: f.mtime
|
|
1436
|
+
});
|
|
1437
|
+
}
|
|
1438
|
+
const edgeMap = /* @__PURE__ */ new Map();
|
|
1439
|
+
for (const f of index.files.values()) {
|
|
1440
|
+
const matches = f.content.matchAll(WIKILINK_RE);
|
|
1441
|
+
for (const m of matches) {
|
|
1442
|
+
const isEmbed = m[1] === "!";
|
|
1443
|
+
const rawTarget = m[2].trim();
|
|
1444
|
+
const target = resolveTargetSimple(rawTarget, index, options);
|
|
1445
|
+
if (!target) continue;
|
|
1446
|
+
if (target.relativePath === f.relativePath) continue;
|
|
1447
|
+
const key = `${f.relativePath}\0${target.relativePath}`;
|
|
1448
|
+
const existing = edgeMap.get(key);
|
|
1449
|
+
if (existing && existing.type === "transclusion" && !isEmbed) continue;
|
|
1450
|
+
edgeMap.set(key, {
|
|
1451
|
+
source: f.relativePath,
|
|
1452
|
+
target: target.relativePath,
|
|
1453
|
+
type: isEmbed ? "transclusion" : "wikilink"
|
|
1454
|
+
});
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1457
|
+
const edges = [...edgeMap.values()];
|
|
1458
|
+
const tagsMap = /* @__PURE__ */ new Map();
|
|
1459
|
+
for (const f of index.files.values()) {
|
|
1460
|
+
const allTags = new Set(f.tags);
|
|
1461
|
+
if (options.views.parseInlineTags) {
|
|
1462
|
+
for (const tm of f.content.matchAll(BODY_TAG_RE)) {
|
|
1463
|
+
allTags.add(tm[1]);
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
for (const tag of allTags) {
|
|
1467
|
+
const arr = tagsMap.get(tag) ?? [];
|
|
1468
|
+
arr.push(f);
|
|
1469
|
+
tagsMap.set(tag, arr);
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
const allTagsByFile = /* @__PURE__ */ new Map();
|
|
1473
|
+
for (const f of index.files.values()) {
|
|
1474
|
+
const set = new Set(f.tags);
|
|
1475
|
+
if (options.views.parseInlineTags) {
|
|
1476
|
+
for (const tm of f.content.matchAll(BODY_TAG_RE)) set.add(tm[1]);
|
|
1477
|
+
}
|
|
1478
|
+
allTagsByFile.set(f.relativePath, [...set]);
|
|
1479
|
+
}
|
|
1480
|
+
const tags = {};
|
|
1481
|
+
for (const [tag, files] of tagsMap) {
|
|
1482
|
+
const sorted = [...files].sort((a, b) => b.mtime - a.mtime);
|
|
1483
|
+
tags[tag] = {
|
|
1484
|
+
count: files.length,
|
|
1485
|
+
files: sorted.map((f) => ({
|
|
1486
|
+
id: f.relativePath,
|
|
1487
|
+
url: f.url,
|
|
1488
|
+
title: pickTitle(f),
|
|
1489
|
+
mtime: f.mtime,
|
|
1490
|
+
path: f.relativePath,
|
|
1491
|
+
otherTags: (allTagsByFile.get(f.relativePath) ?? []).filter(
|
|
1492
|
+
(t) => t !== tag
|
|
1493
|
+
)
|
|
1494
|
+
}))
|
|
1495
|
+
};
|
|
1496
|
+
}
|
|
1497
|
+
const mostRecent = [...index.files.values()].sort((a, b) => b.mtime - a.mtime).slice(0, 10).map((f) => ({
|
|
1498
|
+
id: f.relativePath,
|
|
1499
|
+
url: f.url,
|
|
1500
|
+
title: pickTitle(f),
|
|
1501
|
+
mtime: f.mtime
|
|
1502
|
+
}));
|
|
1503
|
+
return {
|
|
1504
|
+
nodes,
|
|
1505
|
+
edges,
|
|
1506
|
+
tags,
|
|
1507
|
+
stats: {
|
|
1508
|
+
totalFiles: index.files.size,
|
|
1509
|
+
totalAssets: index.assets.size,
|
|
1510
|
+
totalWikilinks: edges.length,
|
|
1511
|
+
totalTags: Object.keys(tags).length,
|
|
1512
|
+
totalWarnings: index.warnings.length,
|
|
1513
|
+
mostRecent
|
|
1514
|
+
},
|
|
1515
|
+
meta: { generatedAt: Date.now(), pluginVersion: PLUGIN_VERSION }
|
|
1516
|
+
};
|
|
1517
|
+
}
|
|
1518
|
+
function writeVaultData(index, options) {
|
|
1519
|
+
const data = buildVaultData(index, options);
|
|
1520
|
+
const json = JSON.stringify(data);
|
|
1521
|
+
const publicDir = import_node_path7.default.join(import_node_path7.default.resolve(options.srcDir), "public");
|
|
1522
|
+
import_node_fs6.default.mkdirSync(publicDir, { recursive: true });
|
|
1523
|
+
const out = import_node_path7.default.join(publicDir, options.views.dataFileName);
|
|
1524
|
+
import_node_fs6.default.writeFileSync(out, json, "utf8");
|
|
1525
|
+
return { path: out, bytes: json.length };
|
|
1526
|
+
}
|
|
1527
|
+
function pickTitle(f) {
|
|
1528
|
+
const fm = f.frontmatter;
|
|
1529
|
+
if (fm && typeof fm.title === "string" && fm.title.trim()) {
|
|
1530
|
+
return fm.title.trim();
|
|
1531
|
+
}
|
|
1532
|
+
return f.basename;
|
|
1533
|
+
}
|
|
1534
|
+
function resolveTargetSimple(rawTarget, index, options) {
|
|
1535
|
+
const target = stripMarkdownExt(toPosix(rawTarget));
|
|
1536
|
+
if (!target) return void 0;
|
|
1537
|
+
if (target.includes("/")) {
|
|
1538
|
+
return index.byRelativePath.get(target) ?? index.byRelativePath.get(target + ".md") ?? index.byRelativePath.get(target + ".markdown");
|
|
1539
|
+
}
|
|
1540
|
+
const aliasKey = options.caseSensitive ? target : target.toLowerCase();
|
|
1541
|
+
const aliased = index.byAlias.get(aliasKey);
|
|
1542
|
+
if (aliased) return aliased;
|
|
1543
|
+
const map = options.caseSensitive ? index.byBasename : index.byBasenameLower;
|
|
1544
|
+
const candidates = map.get(
|
|
1545
|
+
options.caseSensitive ? target : target.toLowerCase()
|
|
1546
|
+
);
|
|
1547
|
+
if (!candidates || candidates.length === 0) return void 0;
|
|
1548
|
+
if (candidates.length === 1) return candidates[0];
|
|
1549
|
+
return [...candidates].sort(
|
|
1550
|
+
(a, b) => a.relativePath.split("/").length - b.relativePath.split("/").length
|
|
1551
|
+
)[0];
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1301
1554
|
// src/vite.ts
|
|
1302
1555
|
function stripQueryAndHash(id) {
|
|
1303
1556
|
return id.split("?")[0].split("#")[0];
|
|
@@ -1315,7 +1568,7 @@ function viteAllYouNeed(userOptions = {}) {
|
|
|
1315
1568
|
config(_userViteConfig, _envCtx) {
|
|
1316
1569
|
const srcDirOpt = userOptions.srcDir;
|
|
1317
1570
|
if (!srcDirOpt) return void 0;
|
|
1318
|
-
const abs = toPosix(
|
|
1571
|
+
const abs = toPosix(import_node_path8.default.resolve(srcDirOpt));
|
|
1319
1572
|
return {
|
|
1320
1573
|
server: {
|
|
1321
1574
|
fs: {
|
|
@@ -1333,6 +1586,30 @@ function viteAllYouNeed(userOptions = {}) {
|
|
|
1333
1586
|
});
|
|
1334
1587
|
try {
|
|
1335
1588
|
index = scanVault(resolved);
|
|
1589
|
+
if (resolved.modules.views) {
|
|
1590
|
+
const mdReport = generateViewMarkdown(resolved, index);
|
|
1591
|
+
for (const written of mdReport.written) {
|
|
1592
|
+
cfg.logger.info(`[vitepress-allyouneed] \u751F\u6210\u89C6\u56FE ${written}`);
|
|
1593
|
+
}
|
|
1594
|
+
for (const skipped of mdReport.skipped) {
|
|
1595
|
+
cfg.logger.warn(
|
|
1596
|
+
`[vitepress-allyouneed] \u8DF3\u8FC7 ${skipped.path}: ${skipped.reason}`
|
|
1597
|
+
);
|
|
1598
|
+
}
|
|
1599
|
+
if (mdReport.written.length > 0) {
|
|
1600
|
+
index = scanVault(resolved);
|
|
1601
|
+
}
|
|
1602
|
+
try {
|
|
1603
|
+
const dataReport = writeVaultData(index, resolved);
|
|
1604
|
+
cfg.logger.info(
|
|
1605
|
+
`[vitepress-allyouneed] \u5199 ${dataReport.path} (${dataReport.bytes}B)`
|
|
1606
|
+
);
|
|
1607
|
+
} catch (err) {
|
|
1608
|
+
cfg.logger.warn(
|
|
1609
|
+
`[vitepress-allyouneed] vault-data.json \u5199\u5165\u5931\u8D25: ${err instanceof Error ? err.message : String(err)}`
|
|
1610
|
+
);
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1336
1613
|
if (index.warnings.length > 0) {
|
|
1337
1614
|
const top = index.warnings.slice(0, 10);
|
|
1338
1615
|
for (const w of top) {
|
|
@@ -1361,15 +1638,21 @@ function viteAllYouNeed(userOptions = {}) {
|
|
|
1361
1638
|
handleHotUpdate(ctx) {
|
|
1362
1639
|
if (!index) return;
|
|
1363
1640
|
try {
|
|
1364
|
-
const stat =
|
|
1641
|
+
const stat = import_node_fs7.default.statSync(ctx.file);
|
|
1365
1642
|
if (stat.isFile()) {
|
|
1366
1643
|
updateFile(index, ctx.file, resolved);
|
|
1367
|
-
} else if (!
|
|
1644
|
+
} else if (!import_node_fs7.default.existsSync(ctx.file)) {
|
|
1368
1645
|
removeFile(index, ctx.file, resolved);
|
|
1369
1646
|
}
|
|
1370
1647
|
} catch {
|
|
1371
1648
|
removeFile(index, ctx.file, resolved);
|
|
1372
1649
|
}
|
|
1650
|
+
if (resolved.modules.views) {
|
|
1651
|
+
try {
|
|
1652
|
+
writeVaultData(index, resolved);
|
|
1653
|
+
} catch {
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1373
1656
|
},
|
|
1374
1657
|
/**
|
|
1375
1658
|
* 拦截占位符 URL,**返回真实绝对文件路径**(POSIX 风格)。
|
|
@@ -1410,6 +1693,97 @@ function viteAllYouNeed(userOptions = {}) {
|
|
|
1410
1693
|
return plugin;
|
|
1411
1694
|
}
|
|
1412
1695
|
|
|
1696
|
+
// src/modules/tags/rule.ts
|
|
1697
|
+
var TAG_RE = /^#([\p{L}_][\p{L}\p{N}_/-]*)/u;
|
|
1698
|
+
function isValidPrecedingChar(c) {
|
|
1699
|
+
if (c === void 0) return true;
|
|
1700
|
+
if (/\s/.test(c)) return true;
|
|
1701
|
+
if ("([{,;\u3002,;".includes(c)) return true;
|
|
1702
|
+
return false;
|
|
1703
|
+
}
|
|
1704
|
+
function makeTagRule() {
|
|
1705
|
+
return function tagRule(state, silent) {
|
|
1706
|
+
const start = state.pos;
|
|
1707
|
+
const src = state.src;
|
|
1708
|
+
if (src.charCodeAt(start) !== 35) return false;
|
|
1709
|
+
const prev = start === 0 ? void 0 : src[start - 1];
|
|
1710
|
+
if (!isValidPrecedingChar(prev)) return false;
|
|
1711
|
+
const slice = src.slice(start);
|
|
1712
|
+
const m = TAG_RE.exec(slice);
|
|
1713
|
+
if (!m) return false;
|
|
1714
|
+
const tag = m[1];
|
|
1715
|
+
if (silent) return true;
|
|
1716
|
+
const env = state.env;
|
|
1717
|
+
if (!env.referencedTags) env.referencedTags = /* @__PURE__ */ new Set();
|
|
1718
|
+
env.referencedTags.add(tag);
|
|
1719
|
+
const tagsViewName = env.options?.views?.names?.tags ?? "tags";
|
|
1720
|
+
const urlPrefix = env.options?.views?.urlPrefix ?? "_perspectives_";
|
|
1721
|
+
const base = env.options?.base ?? "/";
|
|
1722
|
+
const prefixSeg = urlPrefix ? `${urlPrefix}/` : "";
|
|
1723
|
+
const href = `${base}${prefixSeg}${tagsViewName}#${encodeURIComponent(tag)}`;
|
|
1724
|
+
const html = `<a class="ayn-tag" data-tag="${escapeHtml(tag)}" href="${escapeHtml(href)}">#${escapeHtml(tag)}</a>`;
|
|
1725
|
+
const token = state.push("html_inline", "", 0);
|
|
1726
|
+
token.content = html;
|
|
1727
|
+
state.pos = start + m[0].length;
|
|
1728
|
+
return true;
|
|
1729
|
+
};
|
|
1730
|
+
}
|
|
1731
|
+
function registerTagsInline(md) {
|
|
1732
|
+
md.inline.ruler.before("link", "allyouneed_tags", makeTagRule());
|
|
1733
|
+
}
|
|
1734
|
+
|
|
1735
|
+
// src/core/views/sidebar-inject.ts
|
|
1736
|
+
function injectViewsSidebar(sidebar, options) {
|
|
1737
|
+
if (options.views.sidebar === false) return sidebar;
|
|
1738
|
+
if (!options.modules.views) return sidebar;
|
|
1739
|
+
const group = buildViewsGroup(options);
|
|
1740
|
+
if (!group) return sidebar;
|
|
1741
|
+
if (Array.isArray(sidebar)) {
|
|
1742
|
+
if (!sidebar.some((it) => it.text === group.text)) sidebar.push(group);
|
|
1743
|
+
return sidebar;
|
|
1744
|
+
}
|
|
1745
|
+
if (sidebar && typeof sidebar === "object") {
|
|
1746
|
+
for (const path of Object.keys(sidebar)) {
|
|
1747
|
+
const arr = sidebar[path];
|
|
1748
|
+
if (Array.isArray(arr) && !arr.some((it) => it.text === group.text)) {
|
|
1749
|
+
arr.push(group);
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
return sidebar;
|
|
1753
|
+
}
|
|
1754
|
+
return [group];
|
|
1755
|
+
}
|
|
1756
|
+
function buildViewsGroup(options) {
|
|
1757
|
+
const { enabled, names, sidebarText, urlPrefix } = options.views;
|
|
1758
|
+
const base = options.base.endsWith("/") ? options.base.slice(0, -1) : options.base;
|
|
1759
|
+
const prefixSeg = urlPrefix ? `/${urlPrefix}` : "";
|
|
1760
|
+
const items = [];
|
|
1761
|
+
if (enabled.graph) {
|
|
1762
|
+
items.push({
|
|
1763
|
+
text: sidebarText.graph,
|
|
1764
|
+
link: `${base}${prefixSeg}/${names.graph}`
|
|
1765
|
+
});
|
|
1766
|
+
}
|
|
1767
|
+
if (enabled.stats) {
|
|
1768
|
+
items.push({
|
|
1769
|
+
text: sidebarText.stats,
|
|
1770
|
+
link: `${base}${prefixSeg}/${names.stats}`
|
|
1771
|
+
});
|
|
1772
|
+
}
|
|
1773
|
+
if (enabled.tags) {
|
|
1774
|
+
items.push({
|
|
1775
|
+
text: sidebarText.tags,
|
|
1776
|
+
link: `${base}${prefixSeg}/${names.tags}`
|
|
1777
|
+
});
|
|
1778
|
+
}
|
|
1779
|
+
if (items.length === 0) return null;
|
|
1780
|
+
return {
|
|
1781
|
+
text: sidebarText.group,
|
|
1782
|
+
collapsed: true,
|
|
1783
|
+
items
|
|
1784
|
+
};
|
|
1785
|
+
}
|
|
1786
|
+
|
|
1413
1787
|
// src/vitepress.ts
|
|
1414
1788
|
function defineConfigWithAllYouNeed(config, pluginOptions = {}) {
|
|
1415
1789
|
const vpExclude = Array.isArray(config.srcExclude) ? config.srcExclude : [];
|
|
@@ -1435,8 +1809,16 @@ function defineConfigWithAllYouNeed(config, pluginOptions = {}) {
|
|
|
1435
1809
|
};
|
|
1436
1810
|
const existingMarkdown = config.markdown ?? {};
|
|
1437
1811
|
const existingConfig = existingMarkdown.config;
|
|
1812
|
+
const resolvedForWrapper = resolveOptions(mergedOptions, {
|
|
1813
|
+
srcDir: mergedOptions.srcDir ?? config.srcDir,
|
|
1814
|
+
base: mergedOptions.base ?? config.base,
|
|
1815
|
+
cleanUrls: mergedOptions.cleanUrls ?? config.cleanUrls
|
|
1816
|
+
});
|
|
1438
1817
|
const newMarkdownConfig = (md) => {
|
|
1439
1818
|
markdown_it_default(md, mergedOptions);
|
|
1819
|
+
if (resolvedForWrapper.modules.views && resolvedForWrapper.views.parseInlineTags) {
|
|
1820
|
+
registerTagsInline(md);
|
|
1821
|
+
}
|
|
1440
1822
|
md.core.ruler.before(
|
|
1441
1823
|
"normalize",
|
|
1442
1824
|
"allyouneed_env_inject",
|
|
@@ -1446,9 +1828,17 @@ function defineConfigWithAllYouNeed(config, pluginOptions = {}) {
|
|
|
1446
1828
|
existingConfig(md);
|
|
1447
1829
|
}
|
|
1448
1830
|
};
|
|
1831
|
+
const themeConfig = config.themeConfig ?? {};
|
|
1832
|
+
if (resolvedForWrapper.modules.views) {
|
|
1833
|
+
themeConfig.sidebar = injectViewsSidebar(
|
|
1834
|
+
themeConfig.sidebar,
|
|
1835
|
+
resolvedForWrapper
|
|
1836
|
+
);
|
|
1837
|
+
}
|
|
1449
1838
|
return {
|
|
1450
1839
|
...config,
|
|
1451
1840
|
vite: newVite,
|
|
1841
|
+
themeConfig,
|
|
1452
1842
|
markdown: {
|
|
1453
1843
|
...existingMarkdown,
|
|
1454
1844
|
config: newMarkdownConfig
|