Skip to content

Commit abc29c9

Browse files
authored
chore: improve changelog generation (#2320)
1 parent 314e231 commit abc29c9

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

src/components/ListChangelogs/ListChangelogs.jsx

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,34 @@ const contexts = {
2929
),
3030
}
3131

32+
const rawContexts = {
33+
keto: require.context(
34+
"!!raw-loader!../../../docs/self-hosted/oel/keto/changelog",
35+
false,
36+
/\.md$/,
37+
),
38+
kratos: require.context(
39+
"!!raw-loader!../../../docs/self-hosted/oel/kratos/changelog",
40+
false,
41+
/\.md$/,
42+
),
43+
oathkeeper: require.context(
44+
"!!raw-loader!../../../docs/self-hosted/oel/oathkeeper/changelog",
45+
false,
46+
/\.md$/,
47+
),
48+
oauth2: require.context(
49+
"!!raw-loader!../../../docs/self-hosted/oel/oauth2/changelog",
50+
false,
51+
/\.md$/,
52+
),
53+
polis: require.context(
54+
"!!raw-loader!../../../docs/self-hosted/oel/polis/changelog",
55+
false,
56+
/\.md$/,
57+
),
58+
}
59+
3260
function baseFromPath(p) {
3361
// "./v1.3.2.md" -> "v1.3.2" ; "./CHANGELOG_2.0.md" -> "CHANGELOG_2.0"
3462
return p.replace("./", "").replace(/\.md$/, "")
@@ -63,20 +91,35 @@ function compareSemverDesc(a, b) {
6391

6492
export default function ListChangelogs({ dir }) {
6593
const ctx = contexts[dir]
94+
const rawCtx = rawContexts[dir]
6695
if (!ctx) return <p>No changelogs for "{dir}"</p>
6796

6897
const keys = ctx.keys().sort(compareSemverDesc)
6998
const Components = keys.map((k) => ctx(k).default)
99+
const raws = rawCtx
100+
? keys.map((k) => {
101+
const mod = rawCtx(k)
102+
return typeof mod === "string" ? mod : mod.default
103+
})
104+
: keys.map(() => "")
70105

71106
return (
72107
<>
73108
{Components.map((Comp, i) => {
74109
const basename = baseFromPath(keys[i])
75110
const version = extractVersion(basename)
76-
// const id = slugify(version);
111+
const raw = raws[i] || ""
112+
const isNoChanges = /no changelog entries found/i.test(raw.trim())
77113
return (
78114
<section key={keys[i]} style={{ marginBottom: "2rem" }}>
79-
<Comp />
115+
{isNoChanges ? (
116+
<>
117+
<Heading as="h2">{version}</Heading>
118+
<p>No changes requiring a changelog in the {version}.</p>
119+
</>
120+
) : (
121+
<Comp />
122+
)}
80123
<hr />
81124
</section>
82125
)

0 commit comments

Comments
 (0)