Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { join, resolve } = require('node:path');
const { parse } = require('node:url');

const clsx = require('clsx');
const { createApiPageMD, createInfoPageMD } = require('docusaurus-plugin-openapi-docs/lib/markdown');
Expand Down Expand Up @@ -292,9 +293,13 @@ module.exports = {
remarkStringify: {
handlers: {
link: (node) => {
const isUrlInternal = isInternal(node.url);
const url = isUrlInternal ? `${config.absoluteUrl}${node.url}` : node.url;
if (node.title?.startsWith('Direct link to')) return '';

const parsedUrl = parse(node.url);
const isUrlInternal = isInternal(parsedUrl, config.absoluteUrl);
const url = isUrlInternal ? `${config.absoluteUrl}${parsedUrl.pathname}.md` : node.url;

if (isUrlInternal && !parsedUrl.pathname) return '';
if (node.title) return `[${node.title}](${url})`;
return url;
},
Expand Down
11 changes: 4 additions & 7 deletions tools/utils/externalLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@ const { parse } = require('node:url');

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

const internalUrls = ['sdk.apify.com'];
const internalUrl = 'docs.apify.com';

/**
* @param {import('url').UrlWithStringQuery} href
*/
exports.isInternal = (href) => {
return internalUrls.some(
(internalUrl) => href.host === internalUrl
|| (!href.protocol && !href.host && (href.pathname || href.hash)),
);
exports.isInternal = (href, hostName) => {
return href.host === hostName || (!href.protocol && !href.host && (href.pathname || href.hash));
};

/**
Expand All @@ -27,7 +24,7 @@ exports.externalLinkProcessor = () => {
) {
const href = parse(node.properties.href);

if (!exports.isInternal(href)) {
if (!exports.isInternal(href, internalUrl)) {
node.properties.target = '_blank';
node.properties.rel = 'noopener';
} else {
Expand Down