File tree Expand file tree Collapse file tree 4 files changed +42
-11
lines changed Expand file tree Collapse file tree 4 files changed +42
-11
lines changed Original file line number Diff line number Diff line change 1+ import { notFound , redirect } from "next/navigation" ;
2+ import { news } from "../data.js" ;
3+
4+ function toKebabCase ( str ) {
5+ return str . toLowerCase ( ) . replace ( / / g, "-" ) ;
6+ }
7+
8+ function slugof ( news ) {
9+ return news . slug || toKebabCase ( news . title ) ;
10+ }
11+
12+ export async function generateStaticParams ( ) {
13+ return news . map ( ( news ) => ( { slug : slugof ( news ) } ) ) ;
14+ }
15+
16+ export async function generateMetadata ( { params} ) {
17+ const { slug} = await params ;
18+ const blog = news . find ( ( news ) => slugof ( news ) === slug ) ;
19+ if ( ! blog ) notFound ( ) ;
20+ return {
21+ title : `${ blog . title } | Recho` ,
22+ } ;
23+ }
24+
25+ export default async function Page ( { params} ) {
26+ const { slug} = await params ;
27+ const blog = news . find ( ( news ) => slugof ( news ) === slug ) ;
28+ if ( ! blog ) notFound ( ) ;
29+ redirect ( blog . link ) ;
30+ }
Original file line number Diff line number Diff line change 1+ export const news = [
2+ {
3+ title : "A Lighter Way to Code with Creativity" ,
4+ publishedAt : "2025-10-01" ,
5+ summary : "Introducing Recho: a light learning and exploration environment." ,
6+ link : "https://medium.com/@subairui/a-lighter-way-to-code-with-creativity-8c0ac739aa6f" ,
7+ author : "Bairui SU" ,
8+ image : "a-ligter-way-to-code-with-creativity.png" ,
9+ slug : "hello-world" ,
10+ } ,
11+ ] ;
Original file line number Diff line number Diff line change 11import { cn } from "../cn.js" ;
2-
3- const news = [
4- {
5- title : "A Lighter Way to Code with Creativity" ,
6- publishedAt : "2025-10-01" ,
7- summary : "Introducing Recho: a light learning and exploration environment." ,
8- link : "https://medium.com/@subairui/a-lighter-way-to-code-with-creativity-8c0ac739aa6f" ,
9- author : "Bairui SU" ,
10- image : "a-ligter-way-to-code-with-creativity.png" ,
11- } ,
12- ] ;
2+ import { news } from "./data.js" ;
133
144export default function News ( ) {
155 return (
You can’t perform that action at this time.
0 commit comments