Skip to content

Commit 0e597aa

Browse files
Remove LLM buttons in md
1 parent f162354 commit 0e597aa

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

docusaurus.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const { createApiPageMD, createInfoPageMD } = require('docusaurus-plugin-openapi
66
const { config } = require('./apify-docs-theme');
77
const { collectSlugs } = require('./tools/utils/collectSlugs');
88
const { externalLinkProcessor } = require('./tools/utils/externalLink');
9+
const { removeLlmButtons } = require('./tools/utils/removeLlmButtons');
910

1011
/** @type {Partial<import('@docusaurus/types').DocusaurusConfig>} */
1112
module.exports = {
@@ -308,6 +309,8 @@ module.exports = {
308309
categoryName: 'Platform documentation',
309310
},
310311
],
312+
// Add custom remark processing to remove LLM button text
313+
remarkPlugins: [removeLlmButtons],
311314
},
312315
},
313316
],

tools/utils/removeLlmButtons.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const { visit } = require('unist-util-visit');
2+
3+
/**
4+
* Remark plugin to remove LLM button text and related elements from markdown content.
5+
* This is used by the @signalwire/docusaurus-plugin-llms-txt plugin to clean up
6+
* the generated markdown files.
7+
*/
8+
function removeLlmButtons() {
9+
return (tree) => {
10+
// Remove text nodes that contain LLM button text
11+
visit(tree, 'text', (node, index, parent) => {
12+
if (node.value && (
13+
node.value.includes('View as Markdown') ||
14+
node.value.includes('Copy for LLM') ||
15+
node.value.includes('View as MarkdownCopy for LLM')
16+
)) {
17+
// Remove the text node
18+
parent.children.splice(index, 1);
19+
return index; // Adjust index after removal
20+
}
21+
});
22+
};
23+
}
24+
25+
module.exports = {
26+
removeLlmButtons,
27+
};

0 commit comments

Comments
 (0)