@apify/docs-theme 1.0.240 → 1.0.241

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.240",
3
+ "version": "1.0.241",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "files": [
package/src/markdown.js CHANGED
@@ -102,14 +102,20 @@ const prettifyPRLinks = () => (tree) => {
102
102
  /**
103
103
  * Adds frontmatter to the markdown content.
104
104
  * @param {string} changelog The markdown content.
105
- * @param {string} title The frontmatter title.
105
+ * @param {object} [opts]
106
+ * @param {string} [opts.title] The frontmatter title.
107
+ * @param {string} [opts.displayedSidebar] The sidebar to display on the changelog page. Omitted from frontmatter if undefined.
106
108
  * @returns {string} The markdown content with frontmatter.
107
109
  */
108
- function addFrontmatter(changelog, title = 'Changelog') {
110
+ function addFrontmatter(changelog, { title = 'Changelog', displayedSidebar } = {}) {
111
+ const fields = [
112
+ `title: ${title}`,
113
+ `sidebar_label: ${title}`,
114
+ ...(displayedSidebar !== undefined ? [`displayed_sidebar: ${displayedSidebar}`] : []),
115
+ `toc_max_heading_level: 3`,
116
+ ];
109
117
  return `---
110
- title: ${title}
111
- sidebar_label: ${title}
112
- toc_max_heading_level: 3
118
+ ${fields.join('\n')}
113
119
  ---
114
120
  ${changelog}`;
115
121
  }
@@ -131,9 +137,11 @@ function escapeMDXCharacters(changelog) {
131
137
  /**
132
138
  * Updates the markdown content for better UX and compatibility with Docusaurus v3.
133
139
  * @param {string} changelog The markdown content.
140
+ * @param {object} [opts]
141
+ * @param {string} [opts.displayedSidebar] The sidebar to display on the changelog page.
134
142
  * @returns {string} The updated markdown content.
135
143
  */
136
- function updateChangelog(changelog) {
144
+ function updateChangelog(changelog, { displayedSidebar } = {}) {
137
145
  const pipeline = unified()
138
146
  .use(remarkParse)
139
147
  .use(removeGitCliffMarkers)
@@ -143,7 +151,7 @@ function updateChangelog(changelog) {
143
151
  .use(remarkStringify);
144
152
 
145
153
  changelog = pipeline.processSync(changelog).toString();
146
- changelog = addFrontmatter(changelog);
154
+ changelog = addFrontmatter(changelog, { displayedSidebar });
147
155
  changelog = escapeMDXCharacters(changelog);
148
156
  return changelog;
149
157
  }
package/src/theme.js CHANGED
@@ -25,7 +25,7 @@ function findPathInParentOrThrow(endPath) {
25
25
  return filePath;
26
26
  }
27
27
 
28
- async function generateChangelogFromGitHubReleases(paths, repo) {
28
+ async function generateChangelogFromGitHubReleases(paths, repo, { displayedSidebar } = {}) {
29
29
  const response = await axios.get(`https://api.github.com/repos/${repo}/releases`);
30
30
  const releases = response.data;
31
31
 
@@ -40,11 +40,11 @@ async function generateChangelogFromGitHubReleases(paths, repo) {
40
40
  });
41
41
 
42
42
  paths.forEach((p) => {
43
- fs.writeFileSync(path.join(p, 'changelog.md'), updateChangelog(markdown));
43
+ fs.writeFileSync(path.join(p, 'changelog.md'), updateChangelog(markdown, { displayedSidebar }));
44
44
  });
45
45
  }
46
46
 
47
- function copyChangelogFromRoot(paths, hasDefaultChangelog) {
47
+ function copyChangelogFromRoot(paths, hasDefaultChangelog, { displayedSidebar } = {}) {
48
48
  const sourceChangelogPath = findPathInParentOrThrow('CHANGELOG.md');
49
49
 
50
50
  for (const docsPath of paths) {
@@ -57,7 +57,7 @@ function copyChangelogFromRoot(paths, hasDefaultChangelog) {
57
57
  }
58
58
 
59
59
  const changelog = fs.readFileSync(sourceChangelogPath, 'utf-8');
60
- fs.writeFileSync(targetChangelogPath, updateChangelog(changelog));
60
+ fs.writeFileSync(targetChangelogPath, updateChangelog(changelog, { displayedSidebar }));
61
61
  }
62
62
  }
63
63
 
@@ -87,6 +87,10 @@ function theme(
87
87
  ),
88
88
  ];
89
89
 
90
+ const { changelogDisplayedSidebar: displayedSidebar } = options;
91
+ const displayedSidebarLine = displayedSidebar !== undefined
92
+ ? `displayed_sidebar: ${displayedSidebar}\n`
93
+ : '';
90
94
  const hasDefaultChangelog = new Map();
91
95
 
92
96
  for (const p of pathsToCopyChangelog) {
@@ -95,7 +99,7 @@ function theme(
95
99
  fs.writeFileSync(`${p}/changelog.md`, `---
96
100
  title: Changelog
97
101
  sidebar_label: Changelog
98
- ---
102
+ ${displayedSidebarLine}---
99
103
  It seems that the changelog is not available.
100
104
  This either means that your Docusaurus setup is misconfigured, or that your GitHub repository contains no releases yet.
101
105
  `);
@@ -103,9 +107,13 @@ This either means that your Docusaurus setup is misconfigured, or that your GitH
103
107
  }
104
108
 
105
109
  if (options.changelogFromRoot) {
106
- copyChangelogFromRoot(pathsToCopyChangelog, hasDefaultChangelog);
110
+ copyChangelogFromRoot(pathsToCopyChangelog, hasDefaultChangelog, { displayedSidebar });
107
111
  } else {
108
- await generateChangelogFromGitHubReleases(pathsToCopyChangelog, `${context.siteConfig.organizationName}/${context.siteConfig.projectName}`);
112
+ await generateChangelogFromGitHubReleases(
113
+ pathsToCopyChangelog,
114
+ `${context.siteConfig.organizationName}/${context.siteConfig.projectName}`,
115
+ { displayedSidebar },
116
+ );
109
117
  }
110
118
  } catch (e) {
111
119
  console.warn(`Changelog page could not be initialized: ${e.message}`);