@apify/docs-theme 1.0.131 → 1.0.133

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apify/docs-theme",
3
- "version": "1.0.131",
3
+ "version": "1.0.133",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "files": [
package/src/markdown.js CHANGED
@@ -1,12 +1,13 @@
1
1
  function updateChangelog(changelog) {
2
- changelog = addHeader(changelog);
2
+ changelog = addFrontmatter(changelog);
3
3
  changelog = pushHeadings(changelog);
4
- changelog = linkUsers(changelog);
5
- changelog = linkPRs(changelog);
4
+ changelog = fixUserLinks(changelog);
5
+ changelog = fixPRLinks(changelog);
6
+ changelog = escapeMDXCharacters(changelog);
6
7
  return changelog;
7
8
  }
8
9
 
9
- function addHeader(changelog, header = 'Changelog') {
10
+ function addFrontmatter(changelog, header = 'Changelog') {
10
11
  return `---
11
12
  title: ${header}
12
13
  sidebar_label: ${header}
@@ -19,14 +20,22 @@ function pushHeadings(changelog) {
19
20
  return changelog.replaceAll(/\n#[^#]/g, '\n## ');
20
21
  }
21
22
 
22
- function linkUsers(changelog) {
23
+ function fixUserLinks(changelog) {
23
24
  return changelog.replaceAll(/by @([a-zA-Z0-9-]+)/g, 'by [@$1](https://github.com/$1)');
24
25
  }
25
26
 
26
- function linkPRs(changelog) {
27
+ function fixPRLinks(changelog) {
27
28
  return changelog.replaceAll(/(((https?:\/\/)?(www.)?)?github.com\/[^\s]*?\/pull\/([0-9]+))/g, '[#$5]($1)');
28
29
  }
29
30
 
31
+ function escapeMDXCharacters(changelog) {
32
+ return changelog.replaceAll(/<|>/g, (match) => {
33
+ return match === '<' ? '&lt;' : '&gt;';
34
+ }).replaceAll(/\{|\}/g, (match) => {
35
+ return match === '{' ? '&#123;' : '&#125;';
36
+ });
37
+ }
38
+
30
39
  module.exports = {
31
40
  updateChangelog,
32
41
  };
package/src/theme.js CHANGED
@@ -25,7 +25,7 @@ function findPathInParentOrThrow(endPath) {
25
25
  return filePath;
26
26
  }
27
27
 
28
- async function copyChangelogFromReleases(paths, repo) {
28
+ async function generateChangelogFromGitHubReleases(paths, repo) {
29
29
  const response = await axios.get(`https://api.github.com/repos/${repo}/releases`);
30
30
  const releases = response.data;
31
31
 
@@ -40,18 +40,24 @@ async function copyChangelogFromReleases(paths, repo) {
40
40
  });
41
41
 
42
42
  paths.forEach((p) => {
43
- fs.writeFileSync(`${p}/changelog.md`, updateChangelog(markdown));
43
+ fs.writeFileSync(path.join(p, 'changelog.md'), updateChangelog(markdown));
44
44
  });
45
45
  }
46
46
 
47
- function copyChangelogFromRoot(paths) {
48
- const changelogPath = findPathInParentOrThrow('CHANGELOG.md');
47
+ function copyChangelogFromRoot(paths, hasDefaultChangelog) {
48
+ const sourceChangelogPath = findPathInParentOrThrow('CHANGELOG.md');
49
49
 
50
50
  for (const docsPath of paths) {
51
- if (fs.existsSync(path.join(docsPath, 'changelog.md')) && fs.statSync(
52
- path.join(docsPath, 'changelog.md')).mtime >= fs.statSync(changelogPath).mtime) continue;
53
- const changelog = fs.readFileSync(changelogPath, 'utf-8');
54
- fs.writeFileSync(`${docsPath}/changelog.md`, updateChangelog(changelog));
51
+ const targetChangelogPath = path.join(docsPath, 'changelog.md');
52
+
53
+ if (fs.existsSync(targetChangelogPath)
54
+ && fs.statSync(targetChangelogPath).mtime >= fs.statSync(sourceChangelogPath).mtime
55
+ && !hasDefaultChangelog.get(docsPath)) {
56
+ continue;
57
+ }
58
+
59
+ const changelog = fs.readFileSync(sourceChangelogPath, 'utf-8');
60
+ fs.writeFileSync(targetChangelogPath, updateChangelog(changelog));
55
61
  }
56
62
  }
57
63
 
@@ -81,6 +87,8 @@ function theme(
81
87
  ),
82
88
  ];
83
89
 
90
+ const hasDefaultChangelog = new Map();
91
+
84
92
  for (const p of pathsToCopyChangelog) {
85
93
  // the changelog page has to exist for the sidebar to work - async loadContent() is (apparently) not awaited for by sidebar
86
94
  if (fs.existsSync(path.join(p, 'changelog.md'))) continue;
@@ -91,12 +99,13 @@ sidebar_label: Changelog
91
99
  It seems that the changelog is not available.
92
100
  This either means that your Docusaurus setup is misconfigured, or that your GitHub repository contains no releases yet.
93
101
  `);
102
+ hasDefaultChangelog.set(p, true);
94
103
  }
95
104
 
96
105
  if (options.changelogFromRoot) {
97
- copyChangelogFromRoot(pathsToCopyChangelog);
106
+ copyChangelogFromRoot(pathsToCopyChangelog, hasDefaultChangelog);
98
107
  } else {
99
- await copyChangelogFromReleases(pathsToCopyChangelog, `${context.siteConfig.organizationName}/${context.siteConfig.projectName}`);
108
+ await generateChangelogFromGitHubReleases(pathsToCopyChangelog, `${context.siteConfig.organizationName}/${context.siteConfig.projectName}`);
100
109
  }
101
110
  } catch (e) {
102
111
  // eslint-disable-next-line no-console
@@ -1,14 +0,0 @@
1
- import CodeBlock from '@theme/CodeBlock';
2
- import React, { isValidElement } from 'react';
3
-
4
- export default function MDXPre(props) {
5
- return (
6
- <CodeBlock
7
- // If this pre is created by a ``` fenced codeblock, unwrap the children
8
- {...(isValidElement(props.children)
9
- && props.children.props?.originalType === 'code'
10
- ? props.children.props
11
- : { ...props })}
12
- />
13
- );
14
- }