Skip to content

Commit ad1bbef

Browse files
authored
feat: Add absolute url to API example (#1977)
Closes #1892 See https://pr-1977.preview.docs.apify.com/api/v2/act-runs-post.md (api.apify.com added)
1 parent 9c2394f commit ad1bbef

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

docusaurus.config.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,29 @@ module.exports = {
304304
if (node.title) return `[${node.title}](${url})`;
305305
return url;
306306
},
307+
code: (node) => {
308+
const apiMethods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'];
309+
const splitValueLines = node.value.trim().split('\n');
310+
311+
splitValueLines.forEach((item, i) => {
312+
if (apiMethods.some((method) => item.trim() === method)) {
313+
// try to parse as URL, if successful, prefix with absolute URL
314+
try {
315+
const parsedUrl = parse(splitValueLines[i + 1]);
316+
if (isInternal(parsedUrl, config.absoluteUrl) && parsedUrl.pathname) {
317+
if (splitValueLines[i + 1]) splitValueLines[i + 1] = `https://api.apify.com${parsedUrl.pathname}`;
318+
}
319+
} catch {
320+
// do nothing, leave the line as is
321+
}
322+
}
323+
});
324+
325+
if (apiMethods.some((method) => node.value.trim().startsWith(method))) {
326+
node.lang = node.lang?.toLowerCase();
327+
}
328+
return `\n\`\`\`${node.lang || ''}\n${splitValueLines.join('\n')}\n\`\`\`\n`;
329+
},
307330
},
308331
},
309332
excludeRoutes: [

0 commit comments

Comments
 (0)