Skip to content

Commit 9c2394f

Browse files
authored
fix: Absolute URL md links (#1959)
Closes #1886 Removed invalid links: - when there's no pathname - fixed links to md files with hash and/or query param - add .md to local links
1 parent 2d63877 commit 9c2394f

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

docusaurus.config.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const { join, resolve } = require('node:path');
2+
const { parse } = require('node:url');
23

34
const clsx = require('clsx');
45
const { createApiPageMD, createInfoPageMD } = require('docusaurus-plugin-openapi-docs/lib/markdown');
@@ -282,6 +283,7 @@ module.exports = {
282283
'@signalwire/docusaurus-plugin-llms-txt',
283284
/** @type {import('@signalwire/docusaurus-plugin-llms-txt').PluginOptions} */
284285
({
286+
siteDescription: 'The entire content of Apify documentation is available in a single Markdown file at https://docs.apify.com/llms-full.txt',
285287
content: {
286288
includeVersionedDocs: false,
287289
enableLlmsFullTxt: true,
@@ -292,9 +294,13 @@ module.exports = {
292294
remarkStringify: {
293295
handlers: {
294296
link: (node) => {
295-
const isUrlInternal = isInternal(node.url);
296-
const url = isUrlInternal ? `${config.absoluteUrl}${node.url}` : node.url;
297+
if (node.title?.startsWith('Direct link to')) return '';
297298

299+
const parsedUrl = parse(node.url);
300+
const isUrlInternal = isInternal(parsedUrl, config.absoluteUrl);
301+
const url = isUrlInternal ? `${config.absoluteUrl}${parsedUrl.pathname}.md` : node.url;
302+
303+
if (isUrlInternal && !parsedUrl.pathname) return '';
298304
if (node.title) return `[${node.title}](${url})`;
299305
return url;
300306
},

tools/utils/externalLink.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@ const { parse } = require('node:url');
22

33
const visit = import('unist-util-visit').then((m) => m.visit);
44

5-
const internalUrls = ['sdk.apify.com'];
5+
const internalUrl = 'docs.apify.com';
66

77
/**
88
* @param {import('url').UrlWithStringQuery} href
99
*/
10-
exports.isInternal = (href) => {
11-
return internalUrls.some(
12-
(internalUrl) => href.host === internalUrl
13-
|| (!href.protocol && !href.host && (href.pathname || href.hash)),
14-
);
10+
exports.isInternal = (href, hostName) => {
11+
return href.host === hostName || (!href.protocol && !href.host && (href.pathname || href.hash));
1512
};
1613

1714
/**
@@ -27,7 +24,7 @@ exports.externalLinkProcessor = () => {
2724
) {
2825
const href = parse(node.properties.href);
2926

30-
if (!exports.isInternal(href)) {
27+
if (!exports.isInternal(href, internalUrl)) {
3128
node.properties.target = '_blank';
3229
node.properties.rel = 'noopener';
3330
} else {

0 commit comments

Comments
 (0)