Skip to content

Commit 244bdf2

Browse files
committed
✨ use page number as href
1 parent e1cfa65 commit 244bdf2

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

packages/plugin-changelog/src/index.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,19 @@ import type {
1919
import type { Options, PluginOptions } from "./options";
2020
import type { ChangelogChunk } from "./types";
2121

22-
export const HEADER = `---
23-
{{extraHeader}}
22+
export const HEADER = ({
23+
extraHeader,
24+
chunkTitle,
25+
}: {
26+
extraHeader: string;
27+
chunkTitle: string;
28+
}): string => `---
29+
${extraHeader}
2430
---
2531
2632
import DocPaginator from "@theme/DocPaginator"
2733
28-
# {{chunkTitle}}
34+
# ${chunkTitle}
2935
`;
3036

3137
function processSection(section: string) {
@@ -95,12 +101,13 @@ export default async function pluginChangelog(
95101
await Promise.all(
96102
chunks.map((chunk, index) =>
97103
fs.outputFile(
98-
path.join(generateDir, getChunkFilename(chunk, index)),
104+
path.join(generateDir, getChunkFilename(index)),
99105
getChunkContent(
100106
chunk,
101-
HEADER.replaceAll("{{extraHeader}}", options.changelogHeader)
102-
.replaceAll("{{position}}", index.toString())
103-
.replaceAll("{{chunkTitle}}", getChunkTitle(chunk)),
107+
HEADER({
108+
extraHeader: options.changelogHeader,
109+
chunkTitle: getChunkTitle(chunk),
110+
}),
104111
) + getPaginator(chunks, index - 1, index + 1),
105112
),
106113
),
@@ -116,6 +123,7 @@ const pluginOptionsSchema = Joi.object<PluginOptions>({
116123
changelogDestPath: Joi.string().default("src/pages/changelog"),
117124
changelogHeader: Joi.string().default(""),
118125
changelogPerPage: Joi.number().default(10),
126+
changelogSidebarID: Joi.string().default("changelog"),
119127
});
120128

121129
export function validateOptions({

packages/plugin-changelog/src/options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export type PluginOptions = {
33
changelogDestPath: string;
44
changelogHeader: string;
55
changelogPerPage: number;
6+
changelogSidebarID: string;
67
};
78

89
export type Options = Partial<PluginOptions>;

packages/plugin-changelog/src/utils.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,16 @@ export function getPaginator(
1818
if (prevIdx >= 0 && prevIdx < chunks.length) {
1919
const chunk = chunks?.[prevIdx]?.[0];
2020
if (chunk) {
21-
const title = prevIdx === 0 ? "" : encodeURIComponent(chunk.title);
22-
content += ` previous={{ title: "${chunk.title}", permalink: "/changelog/${title}" }}`;
21+
const href = prevIdx > 0 ? prevIdx.toString() : "";
22+
content += ` previous={{ title: "${chunk.title}", permalink: "/changelog/${href}" }}`;
2323
}
2424
}
2525

2626
if (nextIdx >= 0 && nextIdx < chunks.length) {
2727
const chunk = chunks?.[nextIdx]?.[0];
2828
if (chunk) {
29-
content += ` next={{ title: "${
30-
chunk.title
31-
}", permalink: "/changelog/${encodeURIComponent(chunk.title)}" }}`;
29+
const href = nextIdx > 0 ? nextIdx.toString() : "";
30+
content += ` next={{ title: "${chunk.title}", permalink: "/changelog/${href}" }}`;
3231
}
3332
}
3433

@@ -49,8 +48,8 @@ export function getChunkContent(chunk: Section[], header: string): string {
4948
return header + finalContent;
5049
}
5150

52-
export function getChunkFilename(chunk: Section[], index: number): string {
53-
return index > 0 ? `${chunk[0]!.title}.mdx` : "index.mdx";
51+
export function getChunkFilename(index: number): string {
52+
return index > 0 ? `${index}.mdx` : "index.mdx";
5453
}
5554

5655
export function getChunkTitle(chunk: Section[]): string {

website/sidebars.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ const sidebars: SidebarsConfig = {
5454
(chunk, index) => ({
5555
type: "link",
5656
label: chunk[0]!.title,
57-
href: `/changelog/${
58-
index > 0 ? encodeURIComponent(chunk[0]!.title) : ""
59-
}`,
57+
href: `/changelog/${index > 0 ? index.toString() : ""}`,
6058
}),
6159
),
6260
},

0 commit comments

Comments
 (0)