hyperbook 0.62.0 → 0.63.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.
Files changed (2) hide show
  1. package/dist/index.js +116 -1
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -63354,6 +63354,116 @@ const lunr_1 = __importDefault(__nccwpck_require__(12203));
63354
63354
  const markdown_1 = __nccwpck_require__(72384);
63355
63355
  const package_json_1 = __importDefault(__nccwpck_require__(8330));
63356
63356
  exports.ASSETS_FOLDER = "__hyperbook_assets";
63357
+ /**
63358
+ * Generates an llms.txt file by combining all markdown files in order
63359
+ */
63360
+ async function generateLlmsTxt(root, rootOut, hyperbookJson, pagesAndSections, version) {
63361
+ const lines = [];
63362
+ // Add header with book name and version
63363
+ lines.push(`<SYSTEM>${hyperbookJson.name} - Version ${version}</SYSTEM>`);
63364
+ lines.push(""); // Empty line after header
63365
+ // Get all book files once to avoid repeated file system operations
63366
+ const allFiles = await fs_1.vfile.listForFolder(root, "book");
63367
+ // Helper function to recursively process sections and pages
63368
+ const processSection = async (section, level = 0) => {
63369
+ // Skip if hidden
63370
+ if (section.hide) {
63371
+ return;
63372
+ }
63373
+ // Add section header if it has content
63374
+ if (section.href && !section.isEmpty) {
63375
+ const file = allFiles.find((f) => f.path.href === section.href);
63376
+ if (file) {
63377
+ // Add section name as a header
63378
+ lines.push(`# ${section.name}`);
63379
+ lines.push("");
63380
+ // Get the markdown content without frontmatter
63381
+ const content = file.markdown.content.trim();
63382
+ if (content) {
63383
+ lines.push(content);
63384
+ lines.push(""); // Empty line after content
63385
+ }
63386
+ }
63387
+ }
63388
+ // Process nested pages
63389
+ if (section.pages) {
63390
+ for (const page of section.pages) {
63391
+ await processPage(page);
63392
+ }
63393
+ }
63394
+ // Process nested sections
63395
+ if (section.sections) {
63396
+ for (const subsection of section.sections) {
63397
+ await processSection(subsection, level + 1);
63398
+ }
63399
+ }
63400
+ };
63401
+ const processPage = async (page) => {
63402
+ // Skip if hidden or empty
63403
+ if (page.hide || page.isEmpty) {
63404
+ return;
63405
+ }
63406
+ if (page.href) {
63407
+ const file = allFiles.find((f) => f.path.href === page.href);
63408
+ if (file) {
63409
+ // Add page name as a header
63410
+ lines.push(`# ${page.name}`);
63411
+ lines.push("");
63412
+ // Get the markdown content without frontmatter
63413
+ const content = file.markdown.content.trim();
63414
+ if (content) {
63415
+ lines.push(content);
63416
+ lines.push(""); // Empty line after content
63417
+ }
63418
+ }
63419
+ }
63420
+ };
63421
+ // Process root-level pages first
63422
+ for (const page of pagesAndSections.pages) {
63423
+ await processPage(page);
63424
+ }
63425
+ // Process sections
63426
+ for (const section of pagesAndSections.sections) {
63427
+ await processSection(section);
63428
+ }
63429
+ // Write the llms.txt file
63430
+ lines.push(`
63431
+ When you are writing a hyperbook syntax you must use markdown plus the documented elements, also keep track of colons. Colons act like parentheses in programming languages. Every opening colon must have a closing colon. For example, in the syntax :bold text: the first colon opens the bold formatting and the second colon closes it. If there is a missing colon, it can lead to formatting errors or unexpected behavior in the rendered output. Always ensure that colons are properly paired to maintain the intended structure and appearance of your hyperbook content.
63432
+
63433
+ Single colons are inline elements.
63434
+
63435
+ Example: :t[Test]
63436
+
63437
+ Double colons are block elements.
63438
+
63439
+ Example: ::p5{src="sketch.js"}
63440
+
63441
+ Triple colons are special elements that can contain other elements inside them.
63442
+
63443
+ Example:
63444
+
63445
+ :::::alert{info}
63446
+
63447
+ ::::tabs
63448
+
63449
+ :::tab{title="JavaScript"}
63450
+
63451
+ Hi
63452
+
63453
+ :::
63454
+
63455
+
63456
+ ::::
63457
+
63458
+ :::::
63459
+
63460
+ When you want to nest elements you need to increase the number of colons by one for each level of nesting. The outer level should have the most colons.
63461
+
63462
+ Also you need to use unique ids when the element supports it.
63463
+ `);
63464
+ const llmsTxtContent = lines.join("\n");
63465
+ await promises_1.default.writeFile(path_1.default.join(rootOut, "llms.txt"), llmsTxtContent);
63466
+ }
63357
63467
  async function runBuildProject(project, rootProject, out, filter) {
63358
63468
  const name = fs_1.hyperproject.getName(project);
63359
63469
  if (project.type === "book") {
@@ -63823,6 +63933,11 @@ const SEARCH_DOCUMENTS = ${JSON.stringify(documents)};
63823
63933
  // GENERATED
63824
63934
  const locales = ${locales};
63825
63935
  `));
63936
+ // Generate llms.txt if enabled
63937
+ if (hyperbookJson.llms) {
63938
+ console.log(`${chalk_1.default.blue(`[${prefix}]`)} Generating llms.txt`);
63939
+ await generateLlmsTxt(root, rootOut, hyperbookJson, pagesAndSections, package_json_1.default.version);
63940
+ }
63826
63941
  console.log(`${chalk_1.default.green(`[${prefix}]`)} Build success: ${rootOut}`);
63827
63942
  }
63828
63943
 
@@ -183326,7 +183441,7 @@ module.exports = /*#__PURE__*/JSON.parse('{"application/1d-interleaved-parityfec
183326
183441
  /***/ ((module) => {
183327
183442
 
183328
183443
  "use strict";
183329
- module.exports = /*#__PURE__*/JSON.parse('{"name":"hyperbook","version":"0.62.0","author":"Mike Barkmin","homepage":"https://github.com/openpatch/hyperbook#readme","license":"MIT","bin":{"hyperbook":"./dist/index.js"},"files":["dist"],"publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/openpatch/hyperbook.git","directory":"packages/hyperbook"},"bugs":{"url":"https://github.com/openpatch/hyperbook/issues"},"engines":{"node":">=12.22.0"},"scripts":{"version":"pnpm build","lint":"tsc --noEmit","dev":"ncc build ./index.ts -w -o dist/","build":"rimraf dist && ncc build ./index.ts -o ./dist/ --no-cache --no-source-map-register --external favicons --external sharp && node postbuild.mjs"},"dependencies":{"favicons":"^7.2.0"},"devDependencies":{"@hyperbook/fs":"workspace:*","@hyperbook/markdown":"workspace:*","@hyperbook/types":"workspace:*","@pnpm/exportable-manifest":"1000.0.6","@types/archiver":"6.0.3","@types/async-retry":"1.4.9","@types/cross-spawn":"6.0.6","@types/lunr":"^2.3.7","@types/prompts":"2.4.9","@types/tar":"6.1.13","@types/ws":"^8.5.14","@vercel/ncc":"0.38.3","archiver":"7.0.1","async-retry":"1.3.3","chalk":"5.4.1","chokidar":"4.0.3","commander":"12.1.0","cpy":"11.1.0","cross-spawn":"7.0.6","domutils":"^3.2.2","extract-zip":"^2.0.1","got":"12.6.0","htmlparser2":"^10.0.0","lunr":"^2.3.9","lunr-languages":"^1.14.0","mime":"^4.0.6","prompts":"2.4.2","rimraf":"6.0.1","tar":"7.4.3","update-check":"1.5.4","ws":"^8.18.0"}}');
183444
+ module.exports = /*#__PURE__*/JSON.parse('{"name":"hyperbook","version":"0.63.0","author":"Mike Barkmin","homepage":"https://github.com/openpatch/hyperbook#readme","license":"MIT","bin":{"hyperbook":"./dist/index.js"},"files":["dist"],"publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/openpatch/hyperbook.git","directory":"packages/hyperbook"},"bugs":{"url":"https://github.com/openpatch/hyperbook/issues"},"engines":{"node":">=12.22.0"},"scripts":{"version":"pnpm build","lint":"tsc --noEmit","dev":"ncc build ./index.ts -w -o dist/","build":"rimraf dist && ncc build ./index.ts -o ./dist/ --no-cache --no-source-map-register --external favicons --external sharp && node postbuild.mjs"},"dependencies":{"favicons":"^7.2.0"},"devDependencies":{"@hyperbook/fs":"workspace:*","@hyperbook/markdown":"workspace:*","@hyperbook/types":"workspace:*","@pnpm/exportable-manifest":"1000.0.6","@types/archiver":"6.0.3","@types/async-retry":"1.4.9","@types/cross-spawn":"6.0.6","@types/lunr":"^2.3.7","@types/prompts":"2.4.9","@types/tar":"6.1.13","@types/ws":"^8.5.14","@vercel/ncc":"0.38.3","archiver":"7.0.1","async-retry":"1.3.3","chalk":"5.4.1","chokidar":"4.0.3","commander":"12.1.0","cpy":"11.1.0","cross-spawn":"7.0.6","domutils":"^3.2.2","extract-zip":"^2.0.1","got":"12.6.0","htmlparser2":"^10.0.0","lunr":"^2.3.9","lunr-languages":"^1.14.0","mime":"^4.0.6","prompts":"2.4.2","rimraf":"6.0.1","tar":"7.4.3","update-check":"1.5.4","ws":"^8.18.0"}}');
183330
183445
 
183331
183446
  /***/ })
183332
183447
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hyperbook",
3
- "version": "0.62.0",
3
+ "version": "0.63.0",
4
4
  "author": "Mike Barkmin",
5
5
  "homepage": "https://github.com/openpatch/hyperbook#readme",
6
6
  "license": "MIT",
@@ -58,7 +58,7 @@
58
58
  "ws": "^8.18.0",
59
59
  "@hyperbook/fs": "0.20.0",
60
60
  "@hyperbook/markdown": "0.37.0",
61
- "@hyperbook/types": "0.17.0"
61
+ "@hyperbook/types": "0.18.0"
62
62
  },
63
63
  "scripts": {
64
64
  "version": "pnpm build",