Skip to content

Commit 9b1619f

Browse files
HonzaTurondaveomri
authored andcommitted
feat: Improve llms.txt (apify#1796)
- Fixing links - Fixing head MD link
1 parent 015f890 commit 9b1619f

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

docusaurus.config.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const { createApiPageMD, createInfoPageMD } = require('docusaurus-plugin-openapi
55

66
const { config } = require('./apify-docs-theme');
77
const { collectSlugs } = require('./tools/utils/collectSlugs');
8-
const { externalLinkProcessor } = require('./tools/utils/externalLink');
8+
const { externalLinkProcessor, isInternal } = require('./tools/utils/externalLink');
99
const { removeLlmButtons } = require('./tools/utils/removeLlmButtons');
1010

1111
/** @type {Partial<import('@docusaurus/types').DocusaurusConfig>} */
@@ -287,14 +287,26 @@ module.exports = {
287287
}),
288288
[
289289
'@signalwire/docusaurus-plugin-llms-txt',
290-
{
290+
/** @type {import('@signalwire/docusaurus-plugin-llms-txt').PluginOptions} */
291+
({
291292
content: {
292293
includeVersionedDocs: false,
293294
enableLlmsFullTxt: true,
294295
includeBlog: true,
295296
includeGeneratedIndex: false,
296297
includePages: true,
297298
relativePaths: false,
299+
remarkStringify: {
300+
handlers: {
301+
link: (node) => {
302+
const isUrlInternal = isInternal(node.url);
303+
const url = isUrlInternal ? `${config.absoluteUrl}${node.url}` : node.url;
304+
305+
if (node.title) return `[${node.title}](${url})`;
306+
return url;
307+
},
308+
},
309+
},
298310
excludeRoutes: [
299311
'/',
300312
],
@@ -319,7 +331,7 @@ module.exports = {
319331
// Add custom remark processing to remove LLM button text
320332
remarkPlugins: [removeLlmButtons],
321333
},
322-
},
334+
}),
323335
],
324336
// TODO this should be somehow computed from all the external sources
325337
// [

tools/utils/externalLink.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ const internalUrls = ['sdk.apify.com'];
77
/**
88
* @param {import('url').UrlWithStringQuery} href
99
*/
10-
function isInternal(href) {
10+
exports.isInternal = (href) => {
1111
return internalUrls.some(
1212
(internalUrl) => href.host === internalUrl
1313
|| (!href.protocol && !href.host && (href.pathname || href.hash)),
1414
);
15-
}
15+
};
1616

1717
/**
1818
* @type {import('unified').Plugin}
@@ -27,7 +27,7 @@ exports.externalLinkProcessor = () => {
2727
) {
2828
const href = parse(node.properties.href);
2929

30-
if (!isInternal(href)) {
30+
if (!exports.isInternal(href)) {
3131
node.properties.target = '_blank';
3232
node.properties.rel = 'noopener';
3333
} else {

0 commit comments

Comments
 (0)