Skip to content

Commit a1800c5

Browse files
authored
fix: do not double wrap GitHub user links in changelog (#1428)
The new `git-cliff`-based workflow in Apify SDK Python already generates the changelog with actual Markdown links for users. Together with the logic from the theme, this caused the userlinks to be "doubled".
1 parent 0fdb424 commit a1800c5

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

apify-docs-theme/src/markdown.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const { visitParents } = require('unist-util-visit-parents');
1111
function updateChangelog(changelog) {
1212
const pipeline = unified()
1313
.use(remarkParse)
14+
.use(removeGitCliffMarkers)
1415
.use(incrementHeadingLevels)
1516
.use(prettifyPRLinks)
1617
.use(linkifyUserTags)
@@ -31,10 +32,21 @@ function updateChangelog(changelog) {
3132
*/
3233
const incrementHeadingLevels = () => (tree) => {
3334
visitParents(tree, 'heading', (node) => {
35+
if (node.depth === 1 && node.children[0].value === 'Changelog') return;
36+
3437
node.depth += 1;
3538
});
3639
};
3740

41+
const removeGitCliffMarkers = () => (tree) => {
42+
visitParents(tree, 'html', (node) => {
43+
const gitCliffMarkerRegex = /generated by git-cliff/ig;
44+
const match = gitCliffMarkerRegex.exec(node.value);
45+
46+
if (match) node.value = '';
47+
});
48+
};
49+
3850
/**
3951
* Links user tags in the markdown content. This function replaces the user tags
4052
* (e.g. `@username`) with a link to the user's GitHub profile (just like GitHub's UI).
@@ -46,9 +58,10 @@ const linkifyUserTags = () => (tree) => {
4658
const userTagRegex = /@([a-zA-Z0-9-]+)(\s|$)/g;
4759
const match = userTagRegex.exec(node.value);
4860

49-
if (!match) return;
50-
5161
const directParent = parents[parents.length - 1];
62+
63+
if (!match || directParent.type === 'link') return;
64+
5265
const nodeIndexInParent = directParent.children.findIndex((x) => x === node);
5366

5467
const username = match[1];

0 commit comments

Comments
 (0)