mdream 0.8.0 → 0.8.2
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.
|
@@ -1492,6 +1492,41 @@ function generateLlmsTxtContent(files, options) {
|
|
|
1492
1492
|
return content;
|
|
1493
1493
|
}
|
|
1494
1494
|
/**
|
|
1495
|
+
* Parse frontmatter from markdown content
|
|
1496
|
+
*/
|
|
1497
|
+
function parseFrontmatter(content) {
|
|
1498
|
+
const frontmatterRegex = /^---\n([\s\S]*?)\n---\n([\s\S]*)$/;
|
|
1499
|
+
const match = content.match(frontmatterRegex);
|
|
1500
|
+
if (!match) return {
|
|
1501
|
+
frontmatter: null,
|
|
1502
|
+
body: content
|
|
1503
|
+
};
|
|
1504
|
+
const frontmatterContent = match[1];
|
|
1505
|
+
const body = match[2];
|
|
1506
|
+
const frontmatter = {};
|
|
1507
|
+
const lines = frontmatterContent.split("\n");
|
|
1508
|
+
for (const line of lines) {
|
|
1509
|
+
const colonIndex = line.indexOf(":");
|
|
1510
|
+
if (colonIndex > 0) {
|
|
1511
|
+
const key = line.substring(0, colonIndex).trim();
|
|
1512
|
+
const value = line.substring(colonIndex + 1).trim();
|
|
1513
|
+
frontmatter[key] = value;
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
return {
|
|
1517
|
+
frontmatter,
|
|
1518
|
+
body
|
|
1519
|
+
};
|
|
1520
|
+
}
|
|
1521
|
+
/**
|
|
1522
|
+
* Serialize frontmatter object to YAML-like format
|
|
1523
|
+
*/
|
|
1524
|
+
function serializeFrontmatter(data) {
|
|
1525
|
+
const lines = [];
|
|
1526
|
+
for (const [key, value] of Object.entries(data)) if (value !== void 0 && value !== null) lines.push(`${key}: ${String(value)}`);
|
|
1527
|
+
return lines.join("\n");
|
|
1528
|
+
}
|
|
1529
|
+
/**
|
|
1495
1530
|
* Generate llms-full.txt content with complete page content
|
|
1496
1531
|
*/
|
|
1497
1532
|
function generateLlmsFullTxtContent(files, options) {
|
|
@@ -1507,13 +1542,27 @@ function generateLlmsFullTxtContent(files, options) {
|
|
|
1507
1542
|
content += `\n---\n\n`;
|
|
1508
1543
|
for (const file of files) {
|
|
1509
1544
|
const url = file.url.startsWith("http://") || file.url.startsWith("https://") ? file.url : origin ? origin + file.url : file.url;
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1545
|
+
const { frontmatter, body } = parseFrontmatter(file.content);
|
|
1546
|
+
const metadata = {
|
|
1547
|
+
title: file.title,
|
|
1548
|
+
url
|
|
1549
|
+
};
|
|
1550
|
+
if (file.filePath && options.outputDir) metadata.file = relative(options.outputDir, file.filePath);
|
|
1551
|
+
else if (file.filePath) metadata.file = file.filePath;
|
|
1552
|
+
if (file.metadata) {
|
|
1553
|
+
if (file.metadata.description) metadata.description = file.metadata.description;
|
|
1554
|
+
if (file.metadata.keywords) metadata.keywords = file.metadata.keywords;
|
|
1555
|
+
if (file.metadata.author) metadata.author = file.metadata.author;
|
|
1556
|
+
}
|
|
1557
|
+
const mergedFrontmatter = frontmatter ? {
|
|
1558
|
+
...frontmatter,
|
|
1559
|
+
...metadata
|
|
1560
|
+
} : metadata;
|
|
1561
|
+
const frontmatterString = serializeFrontmatter(mergedFrontmatter);
|
|
1562
|
+
let contentBody = frontmatter ? body : file.content;
|
|
1563
|
+
const titleLine = contentBody.trim().split("\n")[0];
|
|
1564
|
+
if (titleLine === file.title || titleLine === `# ${file.title}`) contentBody = contentBody.trim().split("\n").slice(1).join("\n").trimStart();
|
|
1565
|
+
content += `---\n${frontmatterString}\n---\n\n${contentBody}\n\n---\n\n`;
|
|
1517
1566
|
}
|
|
1518
1567
|
}
|
|
1519
1568
|
return content;
|
package/dist/cli.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "./_chunks/extraction-D28Kr1J3.mjs";
|
|
2
|
-
import { generateLlmsTxtArtifacts, streamHtmlToMarkdown } from "./_chunks/src-
|
|
2
|
+
import { generateLlmsTxtArtifacts, streamHtmlToMarkdown } from "./_chunks/src-ChFJhyZI.mjs";
|
|
3
3
|
import "./_chunks/plugins-DXY-fo9h.mjs";
|
|
4
4
|
import { withMinimalPreset } from "./_chunks/minimal-CCnrG7a1.mjs";
|
|
5
5
|
import { mkdir, writeFile } from "node:fs/promises";
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { TagIdMap, createPlugin } from "./_chunks/extraction-D28Kr1J3.mjs";
|
|
2
|
-
import { MarkdownProcessor, generateLlmsTxtArtifacts, htmlToMarkdown, parseHtml, streamHtmlToMarkdown } from "./_chunks/src-
|
|
2
|
+
import { MarkdownProcessor, generateLlmsTxtArtifacts, htmlToMarkdown, parseHtml, streamHtmlToMarkdown } from "./_chunks/src-ChFJhyZI.mjs";
|
|
3
3
|
|
|
4
4
|
export { MarkdownProcessor, TagIdMap, createPlugin, generateLlmsTxtArtifacts, htmlToMarkdown, parseHtml, streamHtmlToMarkdown };
|