Skip to content

Commit 878f5b4

Browse files
authored
feat: some llms.txt improvements (#382)
1 parent 1318d28 commit 878f5b4

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/generators/llms-txt/utils/buildApiDocLink.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { transformNodeToString } from '../../../utils/unist.mjs';
1111
*/
1212
export const getEntryDescription = entry => {
1313
if (entry.llm_description) {
14-
return entry.llm_description;
14+
return entry.llm_description.trim();
1515
}
1616

1717
const descriptionNode = entry.content.children.find(

src/utils/unist.mjs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,14 @@ export const transformNodeToString = node => {
1616
return `**${transformNodesToString(node.children)}**`;
1717
case 'emphasis':
1818
return `_${transformNodesToString(node.children)}_`;
19-
default:
20-
return node.children ? transformNodesToString(node.children) : node.value;
19+
default: {
20+
if (node.children) {
21+
return transformNodesToString(node.children);
22+
}
23+
24+
// Replace line breaks (\n) with spaces to keep text in a single line
25+
return node.value?.replace(/\n/g, ' ') || '';
26+
}
2127
}
2228
};
2329

0 commit comments

Comments
 (0)