Skip to content
This repository was archived by the owner on Jan 23, 2024. It is now read-only.

Commit 0052462

Browse files
committed
docs(changelog): implement individual changelog page
1 parent a65e8c5 commit 0052462

File tree

8 files changed

+59
-97
lines changed

8 files changed

+59
-97
lines changed

Diff for: .github/workflows/changelog.yml

-41
This file was deleted.

Diff for: contentlayer.config.ts

+2
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ const Changelog = defineDocumentType(() => ({
170170
title: { type: 'string', required: true },
171171
description: { type: 'string', required: true },
172172
slug: { type: 'string' },
173+
version: { type: 'string' },
173174
},
174175
computedFields: {
175176
frontMatter: {
@@ -178,6 +179,7 @@ const Changelog = defineDocumentType(() => ({
178179
title: doc.title,
179180
description: doc.description,
180181
slug: '/changelog',
182+
version: doc.version,
181183
}),
182184
},
183185
},

Diff for: next-redirect.js

+5
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,11 @@ async function redirect() {
431431
destination: '/community/recipes/:slug',
432432
permanent: true,
433433
},
434+
{
435+
source: '/changelog',
436+
destination: '/changelog/latest',
437+
permanent: true,
438+
},
434439
]
435440
}
436441

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"former-members:gen": "tsx scripts/get-former-members.ts",
1313
"search-meta:gen": "tsx scripts/get-search-meta.ts",
1414
"showcase-data:gen": "tsx scripts/get-showcase-data.ts",
15-
"changelog:gen": "tsx scripts/get-changelog.ts",
1615
"contributing:gen": "tsx scripts/build-contributing-page.ts",
1716
"start": "next start",
1817
"cache:clean": "rm -rf .next .contentlayer",
@@ -97,6 +96,7 @@
9796
"pnpm-deduplicate": "^0.3.1",
9897
"prettier": "^2.7.1",
9998
"react-multi-ref": "^1.0.0",
99+
"semver": "^7.3.7",
100100
"sharp": "^0.30.7",
101101
"tsx": "^3.8.2",
102102
"unified": "^10.1.2",

Diff for: pages/changelog.tsx

-23
This file was deleted.

Diff for: pages/changelog/[version].tsx

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { allChangelogs } from 'contentlayer/generated'
2+
import { InferGetStaticPropsType } from 'next'
3+
import semverMaxSatisfying from 'semver/ranges/max-satisfying'
4+
import { useMDXComponent } from 'next-contentlayer/hooks'
5+
import React from 'react'
6+
import { MDXComponents } from 'components/mdx-components'
7+
import MDXLayout from 'layouts/mdx'
8+
9+
export default function Page({
10+
doc,
11+
}: InferGetStaticPropsType<typeof getStaticProps>) {
12+
const Component = useMDXComponent(doc.body.code)
13+
return (
14+
<MDXLayout frontmatter={doc.frontMatter}>
15+
<Component components={MDXComponents} />
16+
</MDXLayout>
17+
)
18+
}
19+
20+
export const getStaticPaths = () => {
21+
return {
22+
paths: [
23+
...allChangelogs.map((doc) => ({
24+
params: { version: doc.version },
25+
})),
26+
{
27+
params: { version: 'latest' },
28+
},
29+
],
30+
fallback: false,
31+
}
32+
}
33+
34+
export const getStaticProps = async (ctx) => {
35+
let versionParam = ctx.params.version
36+
37+
if (versionParam === 'latest') {
38+
versionParam = semverMaxSatisfying(
39+
allChangelogs.map(({ version }) => version),
40+
'*',
41+
)
42+
}
43+
44+
const doc = allChangelogs.find(({ version }) => version === versionParam)
45+
46+
return {
47+
props: { doc },
48+
}
49+
}

Diff for: pnpm-lock.yaml

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: scripts/get-changelog.ts

-32
This file was deleted.

0 commit comments

Comments
 (0)