Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions app/news/[slug]/page.jsx
Original file line number Diff line number Diff line change
@@ -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);
}
11 changes: 11 additions & 0 deletions app/news/data.js
Original file line number Diff line number Diff line change
@@ -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-world",
},
];
12 changes: 1 addition & 11 deletions app/news/page.jsx
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down