From 50af9463a9ddcfe305b9c5cd439695415f8b24bd Mon Sep 17 00:00:00 2001 From: pearmini Date: Thu, 2 Oct 2025 22:19:20 -0400 Subject: [PATCH 1/2] Add slug for blog --- app/news/[slug]/page.jsx | 30 ++++++++++++++++++++++++++++++ app/news/data.js | 11 +++++++++++ app/news/page.jsx | 12 +----------- 3 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 app/news/[slug]/page.jsx create mode 100644 app/news/data.js diff --git a/app/news/[slug]/page.jsx b/app/news/[slug]/page.jsx new file mode 100644 index 0000000..217abb0 --- /dev/null +++ b/app/news/[slug]/page.jsx @@ -0,0 +1,30 @@ +import {notFound, redirect} from "next/navigation"; +import {news} from "../data.js"; + +function toKebabCase(str) { + return str.toLowerCase().replace(/ /g, "-"); +} + +function slugof(news) { + return news.slug || toKebabCase(news.title); +} + +export async function generateStaticParams() { + return news.map((news) => ({slug: slugof(news)})); +} + +export async function generateMetadata({params}) { + const {slug} = await params; + const blog = news.find((news) => slugof(news) === slug); + if (!blog) notFound(); + return { + title: `${blog.title} | Recho`, + }; +} + +export default async function Page({params}) { + const {slug} = await params; + const blog = news.find((news) => slugof(news) === slug); + if (!blog) notFound(); + redirect(blog.link); +} diff --git a/app/news/data.js b/app/news/data.js new file mode 100644 index 0000000..31c92a5 --- /dev/null +++ b/app/news/data.js @@ -0,0 +1,11 @@ +export const news = [ + { + title: "A Lighter Way to Code with Creativity", + publishedAt: "2025-10-01", + summary: "Introducing Recho: a light learning and exploration environment.", + link: "https://medium.com/@subairui/a-lighter-way-to-code-with-creativity-8c0ac739aa6f", + author: "Bairui SU", + image: "a-ligter-way-to-code-with-creativity.png", + slug: "hello-recho", + }, +]; diff --git a/app/news/page.jsx b/app/news/page.jsx index c2dabda..6fb9a2e 100644 --- a/app/news/page.jsx +++ b/app/news/page.jsx @@ -1,15 +1,5 @@ import {cn} from "../cn.js"; - -const news = [ - { - title: "A Lighter Way to Code with Creativity", - publishedAt: "2025-10-01", - summary: "Introducing Recho: a light learning and exploration environment.", - link: "https://medium.com/@subairui/a-lighter-way-to-code-with-creativity-8c0ac739aa6f", - author: "Bairui SU", - image: "a-ligter-way-to-code-with-creativity.png", - }, -]; +import {news} from "./data.js"; export default function News() { return ( From 4ea5e6a2d8150f6aa7232b6cfd2e4f02277ebf21 Mon Sep 17 00:00:00 2001 From: pearmini Date: Thu, 2 Oct 2025 23:32:47 -0400 Subject: [PATCH 2/2] Update slug --- app/news/data.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/news/data.js b/app/news/data.js index 31c92a5..15cd84f 100644 --- a/app/news/data.js +++ b/app/news/data.js @@ -6,6 +6,6 @@ export const news = [ link: "https://medium.com/@subairui/a-lighter-way-to-code-with-creativity-8c0ac739aa6f", author: "Bairui SU", image: "a-ligter-way-to-code-with-creativity.png", - slug: "hello-recho", + slug: "hello-world", }, ];