Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion apify-docs-theme/src/theme/Layout/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ import { useLocation } from '@docusaurus/router';
// cannot use any of the theme aliases here as it causes a circular dependency :( ideas welcome
import Layout from '@docusaurus/theme-classic/lib/theme/Layout/index';
import useBaseUrl from '@docusaurus/useBaseUrl';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import { usePluginData } from '@docusaurus/useGlobalData';
import React from 'react';

export default function LayoutWrapper(props) {
const { siteConfig } = useDocusaurusContext();
const { options: { subNavbar } } = usePluginData('@apify/docs-theme');
const baseUrl = useBaseUrl('/');
const currentPath = useLocation().pathname.replace(new RegExp(`^${baseUrl}`), '');

return (
<>
<Head>
<link rel="alternate" type="text/markdown" href={`${currentPath}.md`}/>
{currentPath && <link rel="alternate" type="text/markdown" href={`${siteConfig.url}/${currentPath}.md`}/>}
</Head>
<div
style={{
Expand Down
18 changes: 15 additions & 3 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { createApiPageMD, createInfoPageMD } = require('docusaurus-plugin-openapi

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

/** @type {Partial<import('@docusaurus/types').DocusaurusConfig>} */
Expand Down Expand Up @@ -280,14 +280,26 @@ module.exports = {
}),
[
'@signalwire/docusaurus-plugin-llms-txt',
{
/** @type {import('@signalwire/docusaurus-plugin-llms-txt').PluginOptions} */
({
content: {
includeVersionedDocs: false,
enableLlmsFullTxt: true,
includeBlog: true,
includeGeneratedIndex: false,
includePages: true,
relativePaths: false,
remarkStringify: {
handlers: {
link: (node) => {
const isUrlInternal = isInternal(node.url);
const url = isUrlInternal ? `${config.absoluteUrl}${node.url}` : node.url;

if (node.title) return `[${node.title}](${url})`;
return url;
},
},
},
excludeRoutes: [
'/',
],
Expand All @@ -312,7 +324,7 @@ module.exports = {
// Add custom remark processing to remove LLM button text
remarkPlugins: [removeLlmButtons],
},
},
}),
],
// TODO this should be somehow computed from all the external sources
// [
Expand Down
6 changes: 3 additions & 3 deletions tools/utils/externalLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ const internalUrls = ['sdk.apify.com'];
/**
* @param {import('url').UrlWithStringQuery} href
*/
function isInternal(href) {
exports.isInternal = (href) => {
return internalUrls.some(
(internalUrl) => href.host === internalUrl
|| (!href.protocol && !href.host && (href.pathname || href.hash)),
);
}
};

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

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