Skip to content
Merged
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
21 changes: 15 additions & 6 deletions apify-docs-theme/src/markdown.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
function updateChangelog(changelog) {
changelog = addHeader(changelog);
changelog = addFrontmatter(changelog);
changelog = pushHeadings(changelog);
changelog = linkUsers(changelog);
changelog = linkPRs(changelog);
changelog = fixUserLinks(changelog);
changelog = fixPRLinks(changelog);
changelog = escapeMDXCharacters(changelog);
return changelog;
}

function addHeader(changelog, header = 'Changelog') {
function addFrontmatter(changelog, header = 'Changelog') {
return `---
title: ${header}
sidebar_label: ${header}
Expand All @@ -19,14 +20,22 @@ function pushHeadings(changelog) {
return changelog.replaceAll(/\n#[^#]/g, '\n## ');
}

function linkUsers(changelog) {
function fixUserLinks(changelog) {
return changelog.replaceAll(/by @([a-zA-Z0-9-]+)/g, 'by [@$1](https://github.com/$1)');
}

function linkPRs(changelog) {
function fixPRLinks(changelog) {
return changelog.replaceAll(/(((https?:\/\/)?(www.)?)?github.com\/[^\s]*?\/pull\/([0-9]+))/g, '[#$5]($1)');
}

function escapeMDXCharacters(changelog) {
return changelog.replaceAll(/<|>/g, (match) => {
return match === '<' ? '&lt;' : '&gt;';
}).replaceAll(/\{|\}/g, (match) => {
return match === '{' ? '&#123;' : '&#125;';
});
}

module.exports = {
updateChangelog,
};
14 changes: 7 additions & 7 deletions apify-docs-theme/src/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function findPathInParentOrThrow(endPath) {
return filePath;
}

async function copyChangelogFromReleases(paths, repo) {
async function generateChangelogFromGitHubReleases(paths, repo) {
const response = await axios.get(`https://api.github.com/repos/${repo}/releases`);
const releases = response.data;

Expand Down Expand Up @@ -81,6 +81,12 @@ function theme(
),
];

if (options.changelogFromRoot) {
copyChangelogFromRoot(pathsToCopyChangelog);
} else {
await generateChangelogFromGitHubReleases(pathsToCopyChangelog, `${context.siteConfig.organizationName}/${context.siteConfig.projectName}`);
}

for (const p of pathsToCopyChangelog) {
// the changelog page has to exist for the sidebar to work - async loadContent() is (apparently) not awaited for by sidebar
if (fs.existsSync(path.join(p, 'changelog.md'))) continue;
Expand All @@ -92,12 +98,6 @@ It seems that the changelog is not available.
This either means that your Docusaurus setup is misconfigured, or that your GitHub repository contains no releases yet.
`);
}

if (options.changelogFromRoot) {
copyChangelogFromRoot(pathsToCopyChangelog);
} else {
await copyChangelogFromReleases(pathsToCopyChangelog, `${context.siteConfig.organizationName}/${context.siteConfig.projectName}`);
}
} catch (e) {
// eslint-disable-next-line no-console
console.warn(`Changelog page could not be initialized: ${e.message}`);
Expand Down