Skip to content

Commit 396b997

Browse files
authored
docs: stop repeating the section prefix in generated Markdown links (#1070)
Part of apify/apify-web#6665 `@signalwire/docusaurus-plugin-llms-txt@1.2.2` prepends the site URL to link paths that already carry the Docusaurus `baseUrl`, so the generated Markdown points at `https://docs.apify.com/api/client/python/api/client/python/...`, which 404s. It only happens on sites served under a sub-path. The fix is already upstream in `2.0.0-alpha.6`, but it does not look like it will be published soon: npm `latest` is still 1.2.2 and nothing has shipped since `2.0.0-alpha.7` in November 2025. This patch applies that same fix locally. Remove it once a stable 2.x lands. Built here: `llms-full.txt` goes from 4702 doubled links to 0, `llms.txt` stays at 352 correct links. The same patch goes into `apify-cli`, `apify-sdk-js`, `apify-sdk-python` and `apify-client-js`.
1 parent e1808b1 commit 396b997

4 files changed

Lines changed: 45 additions & 2 deletions

File tree

website/docusaurus.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ module.exports = {
158158
includePages: true,
159159
relativePaths: false,
160160
excludeRoutes: [
161+
'/api/client/python/',
161162
'/api/client/python/reference/[0-9]*/**',
162163
'/api/client/python/reference/[0-9]*',
163164
'/api/client/python/reference/next/**',
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
diff --git a/lib/utils/url.js b/lib/utils/url.js
2+
index 0c3168c9128b6abd1a0860b222872b2332dc5ab8..303ac39b92e24c9008924c949ecf91c6746c38cc 100644
3+
--- a/lib/utils/url.js
4+
+++ b/lib/utils/url.js
5+
@@ -56,19 +56,31 @@ export function stripBaseUrl(routePath, baseUrl) {
6+
*/
7+
export function formatUrl(routePath, options, baseUrl = '') {
8+
const { enableMarkdownFiles = true, relativePaths = true, markdownFile, } = options;
9+
+ // routePath and markdownFile may already carry the Docusaurus baseUrl. Strip it, or the
10+
+ // section prefix lands in the URL twice. Stripping before the .md suffix is what keeps a
11+
+ // route that is the site root on the INDEX_MD branch instead of producing '/.md'.
12+
+ const sitePath = relativePaths === false && baseUrl
13+
+ ? (baseUrl.replace(/^[a-z][a-z0-9+.-]*:\/\/[^/]*/i, '') || '/')
14+
+ : null;
15+
// Ensure route path starts with /
16+
let targetPath = ensureLeadingSlash(routePath);
17+
+ if (sitePath) {
18+
+ targetPath = stripBaseUrl(targetPath, sitePath);
19+
+ }
20+
// Use markdown file path if available and enabled
21+
if (enableMarkdownFiles && markdownFile) {
22+
// Ensure markdown file path starts with / for consistency
23+
targetPath = ensureLeadingSlash(markdownFile);
24+
+ if (sitePath) {
25+
+ targetPath = stripBaseUrl(targetPath, sitePath);
26+
+ }
27+
}
28+
else if (enableMarkdownFiles) {
29+
// Add .md extension to route path
30+
targetPath = targetPath === '/' ? INDEX_MD : `${targetPath}.md`;
31+
}
32+
// Handle absolute vs relative paths
33+
- if (relativePaths === false && baseUrl) {
34+
+ if (sitePath) {
35+
return normalizeUrl([baseUrl, targetPath]);
36+
}
37+
// For relative paths, ensure we preserve the leading slash

website/pnpm-lock.yaml

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

website/pnpm-workspace.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ allowBuilds:
1313
'@swc/core': true
1414
core-js: false
1515
unrs-resolver: true
16+
patchedDependencies:
17+
'@signalwire/docusaurus-plugin-llms-txt@1.2.2': patches/@signalwire__docusaurus-plugin-llms-txt@1.2.2.patch

0 commit comments

Comments
 (0)