valaxy 1.2.0 → 1.2.1

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.
@@ -2,7 +2,7 @@ import 'node:path';
2
2
  import 'node:process';
3
3
  import 'yargs';
4
4
  import 'yargs/helpers';
5
- export { c as createCli, s as desktopRuntimeVersion, u as execBuild, O as registerDevCommand, a2 as run, a4 as startValaxyDev } from '../../shared/valaxy.CRodiDWz.mjs';
5
+ export { c as createCli, s as desktopRuntimeVersion, u as execBuild, O as registerDevCommand, a2 as run, a4 as startValaxyDev } from '../../shared/valaxy.DvkRJomf.mjs';
6
6
  import 'node:os';
7
7
  import 'consola';
8
8
  import 'consola/utils';
@@ -25,6 +25,7 @@ import 'mlly';
25
25
  import 'resolve-global';
26
26
  import '@valaxyjs/utils';
27
27
  import 'node:fs';
28
+ import 'picomatch';
28
29
  import 'node:fs/promises';
29
30
  import 'dayjs';
30
31
  import 'feed';
@@ -34,7 +35,6 @@ import 'hookable';
34
35
  import '@unhead/bundler/vite';
35
36
  import 'vitepress-plugin-group-icons';
36
37
  import 'local-pkg';
37
- import 'picomatch';
38
38
  import 'chokidar';
39
39
  import 'unplugin';
40
40
  import 'unplugin-utils';
@@ -1,4 +1,4 @@
1
- export { A as ALL_ROUTE, E as EXCERPT_SEPARATOR, G as GLOBAL_STATE, P as PATHNAME_PROTOCOL_RE, S as StateManager, V as ViteValaxyPlugins, b as build, c as createCli, a as createContentService, d as createMemoryReleasePlugin, e as createServer, f as createValaxyNode, g as createValaxyPlugin, h as customElements, i as defaultSiteConfig, j as defaultValaxyConfig, k as defaultViteConfig, l as defineAddon, m as defineConfig, n as defineSiteConfig, o as defineTheme, p as defineValaxyAddon, q as defineValaxyConfig, r as defineValaxyTheme, s as desktopRuntimeVersion, t as encryptContent, u as execBuild, v as generateClientRedirects, w as getGitTimestamp, x as getIndexHtml, y as getServerInfoText, z as isExternal, B as isInstalledGlobally, C as isKatexEnabled, D as isKatexPluginNeeded, F as isMathJaxEnabled, H as isPath, I as loadAllContent, J as loadConfigFromFile, K as mergeValaxyConfig, L as mergeViteConfigs, M as postProcessForSSG, N as processValaxyOptions, O as registerDevCommand, Q as resolveAddonsConfig, R as resolveFootnoteConfig, T as resolveImportPath, U as resolveImportUrl, W as resolveOptions, X as resolveSiteConfig, Y as resolveSiteConfigFromRoot, Z as resolveThemeConfigFromRoot, _ as resolveThemeValaxyConfig, $ as resolveUserThemeConfig, a0 as resolveValaxyConfig, a1 as resolveValaxyConfigFromRoot, a2 as run, a3 as ssgBuild, a4 as startValaxyDev, a5 as toAtFS, a6 as transformObject, a7 as version } from '../shared/valaxy.CRodiDWz.mjs';
1
+ export { A as ALL_ROUTE, E as EXCERPT_SEPARATOR, G as GLOBAL_STATE, P as PATHNAME_PROTOCOL_RE, S as StateManager, V as ViteValaxyPlugins, b as build, c as createCli, a as createContentService, d as createMemoryReleasePlugin, e as createServer, f as createValaxyNode, g as createValaxyPlugin, h as customElements, i as defaultSiteConfig, j as defaultValaxyConfig, k as defaultViteConfig, l as defineAddon, m as defineConfig, n as defineSiteConfig, o as defineTheme, p as defineValaxyAddon, q as defineValaxyConfig, r as defineValaxyTheme, s as desktopRuntimeVersion, t as encryptContent, u as execBuild, v as generateClientRedirects, w as getGitTimestamp, x as getIndexHtml, y as getServerInfoText, z as isExternal, B as isInstalledGlobally, C as isKatexEnabled, D as isKatexPluginNeeded, F as isMathJaxEnabled, H as isPath, I as loadAllContent, J as loadConfigFromFile, K as mergeValaxyConfig, L as mergeViteConfigs, M as postProcessForSSG, N as processValaxyOptions, O as registerDevCommand, Q as resolveAddonsConfig, R as resolveFootnoteConfig, T as resolveImportPath, U as resolveImportUrl, W as resolveOptions, X as resolveSiteConfig, Y as resolveSiteConfigFromRoot, Z as resolveThemeConfigFromRoot, _ as resolveThemeValaxyConfig, $ as resolveUserThemeConfig, a0 as resolveValaxyConfig, a1 as resolveValaxyConfigFromRoot, a2 as run, a3 as ssgBuild, a4 as startValaxyDev, a5 as toAtFS, a6 as transformObject, a7 as version } from '../shared/valaxy.DvkRJomf.mjs';
2
2
  import 'node:path';
3
3
  import 'consola';
4
4
  import 'fs-extra';
@@ -25,6 +25,7 @@ import 'mlly';
25
25
  import 'resolve-global';
26
26
  import '@valaxyjs/utils';
27
27
  import 'node:fs';
28
+ import 'picomatch';
28
29
  import 'node:fs/promises';
29
30
  import 'dayjs';
30
31
  import 'feed';
@@ -34,7 +35,6 @@ import 'hookable';
34
35
  import '@unhead/bundler/vite';
35
36
  import 'vitepress-plugin-group-icons';
36
37
  import 'local-pkg';
37
- import 'picomatch';
38
38
  import 'chokidar';
39
39
  import 'unplugin';
40
40
  import 'unplugin-utils';
@@ -25,6 +25,7 @@ import { resolvePath } from 'mlly';
25
25
  import { resolveGlobal } from 'resolve-global';
26
26
  import { normalizeRepositoryUrl } from '@valaxyjs/utils';
27
27
  import { existsSync, readFileSync, realpathSync, statSync } from 'node:fs';
28
+ import picomatch from 'picomatch';
28
29
  import { readFile, mkdir, writeFile, realpath, rm, stat } from 'node:fs/promises';
29
30
  import dayjs from 'dayjs';
30
31
  import { Feed } from 'feed';
@@ -34,7 +35,6 @@ import { createHooks } from 'hookable';
34
35
  import { Unhead } from '@unhead/bundler/vite';
35
36
  import { groupIconMdPlugin, groupIconVitePlugin } from 'vitepress-plugin-group-icons';
36
37
  import { isPackageExists } from 'local-pkg';
37
- import picomatch from 'picomatch';
38
38
  import chokidar from 'chokidar';
39
39
  import { createUnplugin } from 'unplugin';
40
40
  import { createFilter } from 'unplugin-utils';
@@ -73,7 +73,7 @@ import * as readline from 'node:readline';
73
73
  import qrcode from 'qrcode';
74
74
  import ejs from 'ejs';
75
75
 
76
- const version = "1.2.0";
76
+ const version = "1.2.1";
77
77
 
78
78
  const GLOBAL_STATE = {
79
79
  valaxyApp: void 0,
@@ -1251,17 +1251,13 @@ function resolveText(value, lang) {
1251
1251
  return nodeT(value, lang);
1252
1252
  return tObject(value, lang);
1253
1253
  }
1254
- async function build$2(options) {
1255
- consola.start("Generating llms.txt ...");
1254
+ const PAGES_SECTION = "Pages";
1255
+ async function loadLlmsPosts(options) {
1256
1256
  const { config } = options;
1257
1257
  const siteConfig = config.siteConfig;
1258
1258
  const llmsConfig = siteConfig.llms;
1259
1259
  const lang = siteConfig.lang || "en";
1260
1260
  loadLocalesYml(path.resolve(options.userRoot, "locales"));
1261
- const siteUrl = getSiteUrl(options);
1262
- if (!siteUrl) {
1263
- consola.warn("`url` is not set in site.config.ts. llms.txt will use relative paths.");
1264
- }
1265
1261
  const include = llmsConfig.include || ["posts/**/*.md"];
1266
1262
  const files = await scanPageFiles(options.userRoot, include);
1267
1263
  const rawPosts = await readPostFiles(files);
@@ -1271,10 +1267,26 @@ async function build$2(options) {
1271
1267
  description: resolveText(data.description, lang) || "",
1272
1268
  date: data.date ? new Date(data.date) : /* @__PURE__ */ new Date(0),
1273
1269
  urlPath: filePathToUrlPath(filePath, options.userRoot),
1270
+ sourcePath: getPagePath(filePath, options.userRoot),
1274
1271
  content,
1275
1272
  rawFrontmatter: stripSensitiveFrontmatter(data)
1276
1273
  }));
1277
1274
  posts.sort((a, b) => +b.date - +a.date);
1275
+ return posts;
1276
+ }
1277
+ async function build$2(options) {
1278
+ consola.start("Generating llms.txt ...");
1279
+ const { config } = options;
1280
+ const siteConfig = config.siteConfig;
1281
+ const llmsConfig = siteConfig.llms;
1282
+ const lang = siteConfig.lang || "en";
1283
+ const siteUrl = getSiteUrl(options);
1284
+ if (!siteUrl) {
1285
+ consola.warn("`url` is not set in site.config.ts. llms.txt will use relative paths.");
1286
+ }
1287
+ const posts = await loadLlmsPosts(options);
1288
+ const selection = llmsSelection(llmsConfig);
1289
+ warnUnmatchedCollapse(posts, selection);
1278
1290
  const distPath = path.resolve(options.userRoot, "dist");
1279
1291
  await fs.ensureDir(distPath);
1280
1292
  const title = resolveText(siteConfig.title, lang) || "Valaxy Blog";
@@ -1284,7 +1296,10 @@ async function build$2(options) {
1284
1296
  description,
1285
1297
  prompt: llmsConfig.prompt,
1286
1298
  posts,
1287
- siteUrl
1299
+ siteUrl,
1300
+ ...selection,
1301
+ sectionOrder: llmsConfig.sectionOrder,
1302
+ featured: llmsConfig.featured
1288
1303
  });
1289
1304
  await fs.writeFile(path.resolve(distPath, "llms.txt"), llmsTxt, "utf-8");
1290
1305
  consola.debug(`[llms] Generated ${colors.dim("dist/llms.txt")}`);
@@ -1293,7 +1308,9 @@ async function build$2(options) {
1293
1308
  title,
1294
1309
  description,
1295
1310
  prompt: llmsConfig.prompt,
1296
- posts
1311
+ posts,
1312
+ exclude: selection.exclude,
1313
+ collapse: selection.collapse
1297
1314
  });
1298
1315
  await fs.writeFile(path.resolve(distPath, "llms-full.txt"), llmsFullTxt, "utf-8");
1299
1316
  consola.debug(`[llms] Generated ${colors.dim("dist/llms-full.txt")}`);
@@ -1312,64 +1329,277 @@ async function build$2(options) {
1312
1329
  }
1313
1330
  consola.success(`llms.txt generated. (${posts.length} pages)`);
1314
1331
  }
1315
- function getSectionName(urlPath) {
1316
- const parts = urlPath.split("/").filter(Boolean);
1317
- if (parts.length >= 2) {
1318
- const dir = parts[0];
1319
- return dir.charAt(0).toUpperCase() + dir.slice(1);
1332
+ function llmsSelection(llms) {
1333
+ return {
1334
+ exclude: llms.exclude,
1335
+ collapse: llms.collapse,
1336
+ locales: llms.locales
1337
+ };
1338
+ }
1339
+ function warnUnmatchedCollapse(posts, selection) {
1340
+ const rules = selection.collapse || [];
1341
+ if (rules.length === 0)
1342
+ return;
1343
+ const { collapseLinks } = planLlmsPages(posts, selection);
1344
+ for (const [index, rule] of rules.entries()) {
1345
+ if (!rule?.match?.trim())
1346
+ continue;
1347
+ if (!collapseLinks.some((link) => link.ruleIndex === index))
1348
+ consola.warn(`[llms] collapse pattern matched no pages: ${rule.match}`);
1320
1349
  }
1321
- return "Pages";
1322
1350
  }
1323
- function generateLlmsTxt(params) {
1324
- const { title, description, prompt, posts, siteUrl } = params;
1325
- const lines = [];
1326
- lines.push(`# ${title}`);
1327
- lines.push("");
1328
- if (description || prompt) {
1351
+ function normalizeGlobPattern(pattern) {
1352
+ return pattern.trim().replace(/^\.\//, "").replace(/^\//, "");
1353
+ }
1354
+ function normalizeLlmsPath(input) {
1355
+ let value = input.trim();
1356
+ if (/^https?:\/\//i.test(value)) {
1357
+ try {
1358
+ value = new URL(value).pathname;
1359
+ } catch {
1360
+ }
1361
+ }
1362
+ if (!value.startsWith("/"))
1363
+ value = `/${value}`;
1364
+ if (value.endsWith("/index.md"))
1365
+ value = value.slice(0, -"/index.md".length);
1366
+ else if (value.endsWith(".md"))
1367
+ value = value.slice(0, -3);
1368
+ if (value.length > 1 && value.endsWith("/"))
1369
+ value = value.slice(0, -1);
1370
+ return value || "/";
1371
+ }
1372
+ function createGlobMatcher(patterns) {
1373
+ const positive = [];
1374
+ const negative = [];
1375
+ for (const value of patterns || []) {
1376
+ const pattern = value.trim();
1377
+ if (pattern.startsWith("!") && !pattern.startsWith("!(")) {
1378
+ const exception = pattern.slice(1);
1379
+ if (!exception.startsWith("!") || exception.startsWith("!("))
1380
+ negative.push(normalizeGlobPattern(exception));
1381
+ } else {
1382
+ positive.push(normalizeGlobPattern(pattern));
1383
+ }
1384
+ }
1385
+ const isMatch = picomatch(positive.filter(Boolean), { windows: false });
1386
+ const isIgnored = picomatch(negative.filter(Boolean), { windows: false });
1387
+ return (sourcePath) => isMatch(sourcePath) && !isIgnored(sourcePath);
1388
+ }
1389
+ function capitalizeSection(segment) {
1390
+ return segment.charAt(0).toUpperCase() + segment.slice(1);
1391
+ }
1392
+ function splitLlmsLocale(urlPath, locales) {
1393
+ const parts = normalizeLlmsPath(urlPath).split("/").filter(Boolean);
1394
+ if (!locales?.length || parts.length === 0)
1395
+ return { parts };
1396
+ const locale = locales.find((item) => item.toLowerCase() === parts[0].toLowerCase());
1397
+ if (!locale)
1398
+ return { parts };
1399
+ return { locale, parts: parts.slice(1) };
1400
+ }
1401
+ function formatLocaleSection(name, locale) {
1402
+ return locale ? `${name} (${locale})` : name;
1403
+ }
1404
+ function getLlmsSectionName(urlPath, locales) {
1405
+ const { locale, parts } = splitLlmsLocale(urlPath, locales);
1406
+ const name = parts.length >= 2 ? capitalizeSection(parts[0]) : PAGES_SECTION;
1407
+ return formatLocaleSection(name, locale);
1408
+ }
1409
+ function sectionFromHref(href, locales, explicit) {
1410
+ if (explicit)
1411
+ return explicit;
1412
+ const normalized = normalizeLlmsPath(href);
1413
+ const named = getLlmsSectionName(normalized, locales);
1414
+ if (named !== PAGES_SECTION && !named.startsWith(`${PAGES_SECTION} (`))
1415
+ return named;
1416
+ const { locale, parts } = splitLlmsLocale(normalized, locales);
1417
+ if (parts.length === 1)
1418
+ return formatLocaleSection(capitalizeSection(parts[0]), locale);
1419
+ return named;
1420
+ }
1421
+ function entryUrl(siteUrl, href) {
1422
+ if (/^https?:\/\//i.test(href))
1423
+ return href;
1424
+ if (href.endsWith(".md"))
1425
+ return siteUrl ? `${siteUrl}${href.startsWith("/") ? href : `/${href}`}` : href;
1426
+ return hrefToUrl(siteUrl, href);
1427
+ }
1428
+ function hrefToUrl(siteUrl, href) {
1429
+ const trimmed = href.trim();
1430
+ if (/^https?:\/\//i.test(trimmed))
1431
+ return trimmed;
1432
+ const directory = trimmed.endsWith("/");
1433
+ const urlPath = trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
1434
+ const target = directory || urlPath.endsWith(".md") ? urlPath : `${normalizeLlmsPath(urlPath)}.md`;
1435
+ return siteUrl ? `${siteUrl}${target}` : target;
1436
+ }
1437
+ function planLlmsPages(posts, config = {}) {
1438
+ const excluded = createGlobMatcher(config.exclude);
1439
+ const rules = config.collapse || [];
1440
+ const matchers = rules.map((rule) => createGlobMatcher(rule?.match ? [rule.match] : []));
1441
+ const matched = /* @__PURE__ */ new Set();
1442
+ const visible = [];
1443
+ for (const post of posts) {
1444
+ if (excluded(post.sourcePath))
1445
+ continue;
1446
+ const ruleIndex = matchers.findIndex((match) => match(post.sourcePath));
1447
+ if (ruleIndex >= 0) {
1448
+ matched.add(ruleIndex);
1449
+ continue;
1450
+ }
1451
+ visible.push(post);
1452
+ }
1453
+ const collapseLinks = [...matched].sort((a, b) => a - b).map((ruleIndex) => {
1454
+ const rule = rules[ruleIndex];
1455
+ return {
1456
+ title: rule.title,
1457
+ description: rule.description || "",
1458
+ href: rule.href,
1459
+ section: sectionFromHref(rule.href, config.locales, rule.section),
1460
+ ruleIndex
1461
+ };
1462
+ });
1463
+ return { visible, collapseLinks };
1464
+ }
1465
+ function appendBlockquote(lines, description, prompt) {
1466
+ const promptLines = prompt ? prompt.split(/\r?\n/) : [];
1467
+ if (!description && promptLines.length === 0)
1468
+ return;
1469
+ if (description)
1470
+ lines.push(`> ${description}`);
1471
+ if (promptLines.length > 0) {
1329
1472
  if (description)
1330
- lines.push(`> ${description}`);
1331
- if (prompt) {
1332
- if (description)
1333
- lines.push(">");
1334
- lines.push(`> ${prompt}`);
1473
+ lines.push(">");
1474
+ for (const line of promptLines)
1475
+ lines.push(line ? `> ${line}` : ">");
1476
+ }
1477
+ lines.push("");
1478
+ }
1479
+ function formatIndexLink(title, url, description) {
1480
+ const desc = description ? `: ${description}` : "";
1481
+ return `- [${title}](${url})${desc}`;
1482
+ }
1483
+ function groupLlmsEntries(params) {
1484
+ const featuredPaths = params.featured?.paths || [];
1485
+ const featuredPosts = [];
1486
+ const rest = [];
1487
+ if (featuredPaths.length > 0) {
1488
+ const byPath = new Map(params.posts.map((post) => [normalizeLlmsPath(post.urlPath), post]));
1489
+ const used = /* @__PURE__ */ new Set();
1490
+ for (const item of featuredPaths) {
1491
+ const post = byPath.get(normalizeLlmsPath(item));
1492
+ if (post && !used.has(post)) {
1493
+ featuredPosts.push(post);
1494
+ used.add(post);
1495
+ }
1335
1496
  }
1336
- lines.push("");
1497
+ for (const post of params.posts) {
1498
+ if (!used.has(post))
1499
+ rest.push(post);
1500
+ }
1501
+ } else {
1502
+ rest.push(...params.posts);
1337
1503
  }
1338
1504
  const sections = /* @__PURE__ */ new Map();
1339
- for (const post of posts) {
1340
- const section = getSectionName(post.urlPath);
1341
- if (!sections.has(section))
1342
- sections.set(section, []);
1343
- sections.get(section).push(post);
1505
+ const featuredTitle = params.featured?.title || "Docs";
1506
+ if (featuredPosts.length > 0) {
1507
+ sections.set(featuredTitle, featuredPosts.map((post) => ({
1508
+ title: post.title,
1509
+ description: post.description,
1510
+ href: `${post.urlPath}.md`
1511
+ })));
1512
+ }
1513
+ for (const post of rest) {
1514
+ const section = getLlmsSectionName(post.urlPath, params.locales);
1515
+ const entries = sections.get(section);
1516
+ const entry = {
1517
+ title: post.title,
1518
+ description: post.description,
1519
+ href: `${post.urlPath}.md`
1520
+ };
1521
+ if (entries)
1522
+ entries.push(entry);
1523
+ else
1524
+ sections.set(section, [entry]);
1525
+ }
1526
+ const collapsed = /* @__PURE__ */ new Map();
1527
+ for (const link of params.collapseLinks) {
1528
+ const entries = collapsed.get(link.section) || [];
1529
+ entries.push({
1530
+ title: link.title,
1531
+ description: link.description,
1532
+ href: link.href
1533
+ });
1534
+ collapsed.set(link.section, entries);
1535
+ }
1536
+ for (const [section, links] of collapsed) {
1537
+ const entries = sections.get(section);
1538
+ if (entries)
1539
+ entries.splice(section === featuredTitle ? featuredPosts.length : 0, 0, ...links);
1540
+ else
1541
+ sections.set(section, links);
1542
+ }
1543
+ return orderSections(sections, params.sectionOrder, featuredPosts.length > 0 ? featuredTitle : void 0);
1544
+ }
1545
+ function orderSections(sections, sectionOrder, featuredTitle) {
1546
+ const entries = [...sections.entries()];
1547
+ if (!sectionOrder?.length)
1548
+ return sections;
1549
+ const byName = new Map(entries.map(([name, items]) => [name.toLowerCase(), [name, items]]));
1550
+ const used = /* @__PURE__ */ new Set();
1551
+ const ordered = [];
1552
+ if (featuredTitle) {
1553
+ const found = byName.get(featuredTitle.toLowerCase());
1554
+ if (found) {
1555
+ ordered.push([found[0], found[1]]);
1556
+ used.add(found[0]);
1557
+ }
1558
+ }
1559
+ for (const name of sectionOrder) {
1560
+ const found = byName.get(name.toLowerCase());
1561
+ if (found && !used.has(found[0])) {
1562
+ ordered.push([found[0], found[1]]);
1563
+ used.add(found[0]);
1564
+ }
1344
1565
  }
1345
- for (const [section, sectionPosts] of sections) {
1566
+ for (const [name, items] of entries) {
1567
+ if (!used.has(name))
1568
+ ordered.push([name, items]);
1569
+ }
1570
+ return new Map(ordered);
1571
+ }
1572
+ function generateLlmsTxt(params) {
1573
+ const { title, description, prompt, posts, siteUrl } = params;
1574
+ const plan = planLlmsPages(posts, params);
1575
+ const sections = groupLlmsEntries({
1576
+ posts: plan.visible,
1577
+ collapseLinks: plan.collapseLinks,
1578
+ locales: params.locales,
1579
+ sectionOrder: params.sectionOrder,
1580
+ featured: params.featured
1581
+ });
1582
+ const lines = [];
1583
+ lines.push(`# ${title}`);
1584
+ lines.push("");
1585
+ appendBlockquote(lines, description, prompt);
1586
+ for (const [section, entries] of sections) {
1346
1587
  lines.push(`## ${section}`);
1347
1588
  lines.push("");
1348
- for (const post of sectionPosts) {
1349
- const mdUrl = siteUrl ? `${siteUrl}${post.urlPath}.md` : `${post.urlPath}.md`;
1350
- const desc = post.description ? `: ${post.description}` : "";
1351
- lines.push(`- [${post.title}](${mdUrl})${desc}`);
1352
- }
1589
+ for (const entry of entries)
1590
+ lines.push(formatIndexLink(entry.title, entryUrl(siteUrl, entry.href), entry.description));
1353
1591
  lines.push("");
1354
1592
  }
1355
1593
  return lines.join("\n");
1356
1594
  }
1357
1595
  function generateLlmsFullTxt(params) {
1358
- const { title, description, prompt, posts } = params;
1596
+ const { title, description, prompt } = params;
1597
+ const { visible } = planLlmsPages(params.posts, params);
1359
1598
  const lines = [];
1360
1599
  lines.push(`# ${title}`);
1361
1600
  lines.push("");
1362
- if (description || prompt) {
1363
- if (description)
1364
- lines.push(`> ${description}`);
1365
- if (prompt) {
1366
- if (description)
1367
- lines.push(">");
1368
- lines.push(`> ${prompt}`);
1369
- }
1370
- lines.push("");
1371
- }
1372
- for (const post of posts) {
1601
+ appendBlockquote(lines, description, prompt);
1602
+ for (const post of visible) {
1373
1603
  lines.push(`## ${post.title}`);
1374
1604
  lines.push("");
1375
1605
  const metaLines = formatMetadataLines(post);
@@ -3767,51 +3997,30 @@ function createLlmsPlugin(options) {
3767
3997
  }
3768
3998
  };
3769
3999
  }
3770
- async function buildLlmsTxt(options) {
3771
- const { config } = options;
3772
- const siteConfig = config.siteConfig;
4000
+ function llmsDocumentInput(options, posts) {
4001
+ const siteConfig = options.config.siteConfig;
3773
4002
  const lang = siteConfig.lang || "en";
3774
- const siteUrl = getSiteUrl(options);
3775
- const posts = await collectPosts(options, lang);
3776
- const title = resolveText(siteConfig.title, lang) || "Valaxy Blog";
3777
- const description = resolveText(siteConfig.description, lang);
3778
- return generateLlmsTxt({
3779
- title,
3780
- description,
3781
- prompt: siteConfig.llms.prompt,
4003
+ const llms = siteConfig.llms;
4004
+ return {
4005
+ title: resolveText(siteConfig.title, lang) || "Valaxy Blog",
4006
+ description: resolveText(siteConfig.description, lang),
4007
+ prompt: llms.prompt,
3782
4008
  posts,
3783
- siteUrl
3784
- });
4009
+ siteUrl: getSiteUrl(options),
4010
+ exclude: llms.exclude,
4011
+ locales: llms.locales,
4012
+ sectionOrder: llms.sectionOrder,
4013
+ featured: llms.featured,
4014
+ collapse: llms.collapse
4015
+ };
3785
4016
  }
3786
- async function buildLlmsFullTxt(options) {
3787
- const { config } = options;
3788
- const siteConfig = config.siteConfig;
3789
- const lang = siteConfig.lang || "en";
3790
- const posts = await collectPosts(options, lang);
3791
- const title = resolveText(siteConfig.title, lang) || "Valaxy Blog";
3792
- const description = resolveText(siteConfig.description, lang);
3793
- return generateLlmsFullTxt({
3794
- title,
3795
- description,
3796
- prompt: siteConfig.llms.prompt,
3797
- posts
3798
- });
4017
+ async function buildLlmsTxt(options) {
4018
+ const posts = await loadLlmsPosts(options);
4019
+ return generateLlmsTxt(llmsDocumentInput(options, posts));
3799
4020
  }
3800
- async function collectPosts(options, lang) {
3801
- const include = options.config.siteConfig.llms.include || ["posts/**/*.md"];
3802
- const files = await scanPageFiles(options.userRoot, include);
3803
- const rawPosts = await readPostFiles(files);
3804
- const publicPosts = filterPublicPosts(rawPosts);
3805
- const posts = publicPosts.map(({ data, content, filePath }) => ({
3806
- title: resolveText(data.title, lang) || path.basename(filePath, ".md"),
3807
- description: resolveText(data.description, lang) || "",
3808
- date: data.date ? new Date(data.date) : /* @__PURE__ */ new Date(0),
3809
- urlPath: filePathToUrlPath(filePath, options.userRoot),
3810
- content,
3811
- rawFrontmatter: stripSensitiveFrontmatter(data)
3812
- }));
3813
- posts.sort((a, b) => +b.date - +a.date);
3814
- return posts;
4021
+ async function buildLlmsFullTxt(options) {
4022
+ const posts = await loadLlmsPosts(options);
4023
+ return generateLlmsFullTxt(llmsDocumentInput(options, posts));
3815
4024
  }
3816
4025
  async function resolveRawMd(url, options) {
3817
4026
  const page = url.slice(1);
@@ -3829,6 +4038,7 @@ async function resolveRawMd(url, options) {
3829
4038
  title: resolveText(data.title, lang) || path.basename(filePath, ".md"),
3830
4039
  description: resolveText(data.description, lang) || "",
3831
4040
  date: data.date ? new Date(data.date) : /* @__PURE__ */ new Date(0),
4041
+ sourcePath: getPagePath(filePath, options.userRoot),
3832
4042
  rawFrontmatter: cleanedFrontmatter
3833
4043
  };
3834
4044
  const header = formatMetadataHeader(post);
@@ -947,6 +947,41 @@ interface SiteConfig {
947
947
  * @default ['posts\/**\/*.md']
948
948
  */
949
949
  include?: string[];
950
+ /**
951
+ * @zh 从 `llms.txt` 和 `llms-full.txt` 排除的 glob(相对于 `pages/`,语法与 `include` 相同)。
952
+ * `files` 仍会写出对应的 `.md` 文件。
953
+ * 不设置时不做排除,因此只开启 `enable` 的站点保持原有输出。
954
+ * @en Glob patterns, relative to `pages/` and using the same syntax as `include`, omitted from `llms.txt` and `llms-full.txt`.
955
+ * Individual `.md` files are still written when `files` is true.
956
+ * Unset means nothing is excluded, so sites that only enable llms keep their previous output.
957
+ */
958
+ exclude?: string[];
959
+ /**
960
+ * @zh `llms.txt` 分组标题的顺序,例如 `['Guide', 'Posts']`。未列出的分组按原顺序排在后面。匹配时忽略大小写。
961
+ * @en Section headings in `llms.txt`, first to last, for example `['Guide', 'Posts']`. Headings you omit keep their original order after these. Matching ignores case.
962
+ */
963
+ sectionOrder?: string[];
964
+ /**
965
+ * @zh 作为语言而不是栏目的 URL 前缀,例如 `['zh']`。
966
+ * `/zh/guide/why` 会归入 `Guide (zh)`,而不是把所有中文页放进一个 `Zh` 分组。
967
+ * 不设置时仍用路径的第一段作为分组名。
968
+ * @en URL prefixes that are languages rather than sections, for example `['zh']`.
969
+ * `/zh/guide/why` is grouped as `Guide (zh)` instead of placing every Chinese page in one `Zh` section.
970
+ * Unset keeps the first path segment as the section name.
971
+ */
972
+ locales?: string[];
973
+ /**
974
+ * @zh 在 `llms.txt` 开头置顶的页面。
975
+ * @en Pages pinned to the start of `llms.txt`.
976
+ */
977
+ featured?: LlmsFeatured;
978
+ /**
979
+ * @zh 把一批页面折叠成 `llms.txt` 中的一条链接,并从不写入 `llms-full.txt`。
980
+ * 对应的 `.md` 文件仍会生成。适合把 API 参考收成一个 `/api/` 入口。
981
+ * @en Replace a set of pages with one `llms.txt` link and omit them from `llms-full.txt`.
982
+ * The `.md` files are still generated. Use this to collapse an API reference to a single `/api/` entry.
983
+ */
984
+ collapse?: LlmsCollapse[];
950
985
  };
951
986
  /**
952
987
  * @description:en-US client redirect rules
@@ -957,6 +992,52 @@ interface SiteConfig {
957
992
  rules?: RedirectRule[];
958
993
  };
959
994
  }
995
+ /**
996
+ * One `llms.txt` link that stands in for every page matching `match`.
997
+ */
998
+ interface LlmsCollapse {
999
+ /**
1000
+ * @zh 相对于 `pages/` 的 glob,语法与 `include` 相同,例如 `api/**\/*.md`。
1001
+ * @en Glob relative to `pages/`, same syntax as `include`, for example `api/**\/*.md`.
1002
+ */
1003
+ match: string;
1004
+ /**
1005
+ * @zh 索引里这条链接的标题
1006
+ * @en Title of the index link
1007
+ */
1008
+ title: string;
1009
+ /**
1010
+ * @zh 链接路径。以 `/` 结尾时保持目录地址(如 `/api/`);否则像普通条目一样补上 `.md`。
1011
+ * @en Link path. A trailing slash stays a directory URL (for example `/api/`). Other paths gain a `.md` suffix, like normal entries.
1012
+ */
1013
+ href: string;
1014
+ /**
1015
+ * @zh 可选描述,写在链接后面
1016
+ * @en Optional description appended after the link
1017
+ */
1018
+ description?: string;
1019
+ /**
1020
+ * @zh 可选分组标题。默认由 `href` 推断:`/api/` 为 `Api`;设置 `locales: ['zh']` 时 `/zh/api/` 为 `Api (zh)`。
1021
+ * @en Optional section heading. Defaults from `href`: `/api/` becomes `Api`, and `/zh/api/` becomes `Api (zh)` when `locales` includes `zh`.
1022
+ */
1023
+ section?: string;
1024
+ }
1025
+ /**
1026
+ * Pages lifted to the front of `llms.txt`.
1027
+ */
1028
+ interface LlmsFeatured {
1029
+ /**
1030
+ * @zh 置顶分组的标题
1031
+ * @en Heading for the leading section
1032
+ * @default 'Docs'
1033
+ */
1034
+ title?: string;
1035
+ /**
1036
+ * @zh 按此顺序置顶的站点路径,例如 `/guide/getting-started`。这些页面不会在后面的分组里再次出现。
1037
+ * @en Site paths pinned first, in this order, for example `/guide/getting-started`. They are not repeated in later sections.
1038
+ */
1039
+ paths: string[];
1040
+ }
960
1041
  type PartialDeep<T> = {
961
1042
  [P in keyof T]?: T[P] extends object ? PartialDeep<T[P]> : T[P];
962
1043
  };
@@ -1020,4 +1101,4 @@ type UserSiteConfig = PartialDeep<SiteConfig>;
1020
1101
  type UserValaxyConfig<ThemeConfig = DefaultTheme.Config> = PartialDeep<ValaxyConfig<ThemeConfig>>;
1021
1102
 
1022
1103
  export { DefaultTheme as D };
1023
- export type { Album as A, BaseFrontMatter as B, ExcerptType as E, FuseListItem as F, PartialDeep as P, RuntimeConfig as R, SiteConfig as S, UserSiteConfig as U, ValaxyConfig as V, RedirectItem as a, ValaxyAddon as b, Post as c, Page as d, PageFrontMatter as e, Photo as f, Pkg as g, PostFrontMatter as h, RedirectRule as i, SocialLink as j, UserValaxyConfig as k };
1104
+ export type { Album as A, BaseFrontMatter as B, ExcerptType as E, FuseListItem as F, LlmsCollapse as L, PartialDeep as P, RuntimeConfig as R, SiteConfig as S, UserSiteConfig as U, ValaxyConfig as V, RedirectItem as a, ValaxyAddon as b, Post as c, LlmsFeatured as d, Page as e, PageFrontMatter as f, Photo as g, Pkg as h, PostFrontMatter as i, RedirectRule as j, SocialLink as k, UserValaxyConfig as l };
@@ -1,5 +1,5 @@
1
- import { c as Post } from '../shared/valaxy.BGgY-Hwl.mjs';
2
- export { A as Album, B as BaseFrontMatter, D as DefaultTheme, E as ExcerptType, F as FuseListItem, d as Page, e as PageFrontMatter, P as PartialDeep, f as Photo, g as Pkg, h as PostFrontMatter, a as RedirectItem, i as RedirectRule, R as RuntimeConfig, S as SiteConfig, j as SocialLink, U as UserSiteConfig, k as UserValaxyConfig, b as ValaxyAddon, V as ValaxyConfig } from '../shared/valaxy.BGgY-Hwl.mjs';
1
+ import { c as Post } from '../shared/valaxy.EzGcrVef.mjs';
2
+ export { A as Album, B as BaseFrontMatter, D as DefaultTheme, E as ExcerptType, F as FuseListItem, L as LlmsCollapse, d as LlmsFeatured, e as Page, f as PageFrontMatter, P as PartialDeep, g as Photo, h as Pkg, i as PostFrontMatter, a as RedirectItem, j as RedirectRule, R as RuntimeConfig, S as SiteConfig, k as SocialLink, U as UserSiteConfig, l as UserValaxyConfig, b as ValaxyAddon, V as ValaxyConfig } from '../shared/valaxy.EzGcrVef.mjs';
3
3
  import { Header } from '@valaxyjs/utils';
4
4
  import '@vueuse/integrations/useFuse';
5
5
  import 'medium-zoom';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "valaxy",
3
3
  "type": "module",
4
- "version": "1.2.0",
4
+ "version": "1.2.1",
5
5
  "description": "📄 Vite & Vue powered static blog generator.",
6
6
  "author": {
7
7
  "email": "me@yunyoujun.cn",
@@ -69,14 +69,14 @@
69
69
  "@antfu/utils": "^9.3.0",
70
70
  "@clack/prompts": "^1.8.1",
71
71
  "@iconify-json/ri": "^1.2.10",
72
- "@intlify/unplugin-vue-i18n": "11.2.7",
72
+ "@intlify/unplugin-vue-i18n": "11.2.8",
73
73
  "@shikijs/transformers": "^4.4.3",
74
74
  "@types/katex": "^0.16.8",
75
75
  "@unhead/bundler": "^3.4.1",
76
76
  "@unhead/schema-org": "^3.4.1",
77
77
  "@unhead/vue": "^3.4.1",
78
- "@valaxyjs/devtools": "1.2.0",
79
- "@valaxyjs/utils": "1.2.0",
78
+ "@valaxyjs/devtools": "1.2.1",
79
+ "@valaxyjs/utils": "1.2.1",
80
80
  "@vitejs/devtools": "0.8.0",
81
81
  "@vitejs/plugin-vue": "^6.0.9",
82
82
  "@vueuse/core": "^15.0.0",
@@ -106,7 +106,7 @@
106
106
  "lru-cache": "^11.5.3",
107
107
  "magic-string": "^1.4.3",
108
108
  "markdown-exit": "^1.3.0",
109
- "markdown-it": "^15.0.2",
109
+ "markdown-it": "^15.0.3",
110
110
  "markdown-it-anchor": "^10.0.0",
111
111
  "markdown-it-attrs": "^5.0.1",
112
112
  "markdown-it-container": "^4.0.0",
@@ -142,11 +142,11 @@
142
142
  "unplugin-vue-components": "32.1.0",
143
143
  "unplugin-vue-markdown": "^32.1.1",
144
144
  "vanilla-lazyload": "^19.1.3",
145
- "vite": "^8.3.0",
145
+ "vite": "^8.3.6",
146
146
  "vite-plugin-vue-devtools": "^8.2.1",
147
147
  "vite-ssg-sitemap": "^0.10.0",
148
148
  "vitepress-plugin-group-icons": "^1.7.6",
149
- "vue-i18n": "^11.4.12",
149
+ "vue-i18n": "^11.4.18",
150
150
  "yargs": "^18.1.0"
151
151
  },
152
152
  "devDependencies": {
package/types/config.ts CHANGED
@@ -480,6 +480,41 @@ export interface SiteConfig {
480
480
  * @default ['posts\/**\/*.md']
481
481
  */
482
482
  include?: string[]
483
+ /**
484
+ * @zh 从 `llms.txt` 和 `llms-full.txt` 排除的 glob(相对于 `pages/`,语法与 `include` 相同)。
485
+ * `files` 仍会写出对应的 `.md` 文件。
486
+ * 不设置时不做排除,因此只开启 `enable` 的站点保持原有输出。
487
+ * @en Glob patterns, relative to `pages/` and using the same syntax as `include`, omitted from `llms.txt` and `llms-full.txt`.
488
+ * Individual `.md` files are still written when `files` is true.
489
+ * Unset means nothing is excluded, so sites that only enable llms keep their previous output.
490
+ */
491
+ exclude?: string[]
492
+ /**
493
+ * @zh `llms.txt` 分组标题的顺序,例如 `['Guide', 'Posts']`。未列出的分组按原顺序排在后面。匹配时忽略大小写。
494
+ * @en Section headings in `llms.txt`, first to last, for example `['Guide', 'Posts']`. Headings you omit keep their original order after these. Matching ignores case.
495
+ */
496
+ sectionOrder?: string[]
497
+ /**
498
+ * @zh 作为语言而不是栏目的 URL 前缀,例如 `['zh']`。
499
+ * `/zh/guide/why` 会归入 `Guide (zh)`,而不是把所有中文页放进一个 `Zh` 分组。
500
+ * 不设置时仍用路径的第一段作为分组名。
501
+ * @en URL prefixes that are languages rather than sections, for example `['zh']`.
502
+ * `/zh/guide/why` is grouped as `Guide (zh)` instead of placing every Chinese page in one `Zh` section.
503
+ * Unset keeps the first path segment as the section name.
504
+ */
505
+ locales?: string[]
506
+ /**
507
+ * @zh 在 `llms.txt` 开头置顶的页面。
508
+ * @en Pages pinned to the start of `llms.txt`.
509
+ */
510
+ featured?: LlmsFeatured
511
+ /**
512
+ * @zh 把一批页面折叠成 `llms.txt` 中的一条链接,并从不写入 `llms-full.txt`。
513
+ * 对应的 `.md` 文件仍会生成。适合把 API 参考收成一个 `/api/` 入口。
514
+ * @en Replace a set of pages with one `llms.txt` link and omit them from `llms-full.txt`.
515
+ * The `.md` files are still generated. Use this to collapse an API reference to a single `/api/` entry.
516
+ */
517
+ collapse?: LlmsCollapse[]
483
518
  }
484
519
 
485
520
  /**
@@ -492,6 +527,54 @@ export interface SiteConfig {
492
527
  }
493
528
  }
494
529
 
530
+ /**
531
+ * One `llms.txt` link that stands in for every page matching `match`.
532
+ */
533
+ export interface LlmsCollapse {
534
+ /**
535
+ * @zh 相对于 `pages/` 的 glob,语法与 `include` 相同,例如 `api/**\/*.md`。
536
+ * @en Glob relative to `pages/`, same syntax as `include`, for example `api/**\/*.md`.
537
+ */
538
+ match: string
539
+ /**
540
+ * @zh 索引里这条链接的标题
541
+ * @en Title of the index link
542
+ */
543
+ title: string
544
+ /**
545
+ * @zh 链接路径。以 `/` 结尾时保持目录地址(如 `/api/`);否则像普通条目一样补上 `.md`。
546
+ * @en Link path. A trailing slash stays a directory URL (for example `/api/`). Other paths gain a `.md` suffix, like normal entries.
547
+ */
548
+ href: string
549
+ /**
550
+ * @zh 可选描述,写在链接后面
551
+ * @en Optional description appended after the link
552
+ */
553
+ description?: string
554
+ /**
555
+ * @zh 可选分组标题。默认由 `href` 推断:`/api/` 为 `Api`;设置 `locales: ['zh']` 时 `/zh/api/` 为 `Api (zh)`。
556
+ * @en Optional section heading. Defaults from `href`: `/api/` becomes `Api`, and `/zh/api/` becomes `Api (zh)` when `locales` includes `zh`.
557
+ */
558
+ section?: string
559
+ }
560
+
561
+ /**
562
+ * Pages lifted to the front of `llms.txt`.
563
+ */
564
+ export interface LlmsFeatured {
565
+ /**
566
+ * @zh 置顶分组的标题
567
+ * @en Heading for the leading section
568
+ * @default 'Docs'
569
+ */
570
+ title?: string
571
+ /**
572
+ * @zh 按此顺序置顶的站点路径,例如 `/guide/getting-started`。这些页面不会在后面的分组里再次出现。
573
+ * @en Site paths pinned first, in this order, for example `/guide/getting-started`. They are not repeated in later sections.
574
+ */
575
+ paths: string[]
576
+ }
577
+
495
578
  export type PartialDeep<T> = {
496
579
  [P in keyof T]?: T[P] extends object ? PartialDeep<T[P]> : T[P]
497
580
  }