Skip to content

Commit 270256e

Browse files
committed
feat: Fix markdown alternate & add absolute links
1 parent 7aa9a81 commit 270256e

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

apify-docs-theme/src/theme/Layout/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default function LayoutWrapper(props) {
1616
return (
1717
<>
1818
<Head>
19-
<link rel="alternate" type="text/markdown" href={`${siteConfig.url}/${currentPath}.md`}/>
19+
{currentPath && <link rel="alternate" type="text/markdown" href={`${siteConfig.url}/${currentPath}.md`}/>}
2020
</Head>
2121
<div
2222
style={{

docusaurus.config.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const { createApiPageMD } = require('docusaurus-plugin-openapi-docs/lib/markdown
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

1010
/** @type {Partial<import('@docusaurus/types').DocusaurusConfig>} */
1111
module.exports = {
@@ -264,14 +264,23 @@ module.exports = {
264264
}),
265265
[
266266
'@signalwire/docusaurus-plugin-llms-txt',
267-
{
267+
/** @type {import('@signalwire/docusaurus-plugin-llms-txt').PluginOptions} */
268+
({
268269
content: {
269270
includeVersionedDocs: false,
270271
enableLlmsFullTxt: true,
271272
includeBlog: true,
272273
includeGeneratedIndex: false,
273274
includePages: true,
274275
relativePaths: false,
276+
remarkStringify: {
277+
handlers: {
278+
link: (node) => {
279+
const isUrlInternal = isInternal(node.url);
280+
return `[${node.title}](${isUrlInternal ? `${config.absoluteUrl}${node.url}` : node.url})`;
281+
},
282+
},
283+
},
275284
excludeRoutes: [
276285
'/',
277286
],
@@ -294,7 +303,7 @@ module.exports = {
294303
},
295304
],
296305
},
297-
},
306+
}),
298307
],
299308
// TODO this should be somehow computed from all the external sources
300309
// [

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)