static params
This commit is contained in:
parent
16f92f90d6
commit
52507b1ed3
2 changed files with 10 additions and 2 deletions
|
|
@ -1,6 +1,14 @@
|
||||||
import Link from "next/link"
|
import Link from "next/link"
|
||||||
import {ArrowLeftIcon} from "@heroicons/react/24/solid"
|
import {ArrowLeftIcon} from "@heroicons/react/24/solid"
|
||||||
import {getArticleData} from "@/lib/articles";
|
import {getArticleData, getSortedArticles} from "@/lib/articles";
|
||||||
|
|
||||||
|
export async function generateStaticParams() {
|
||||||
|
const articles = getSortedArticles();
|
||||||
|
|
||||||
|
return articles.map((article) => ({
|
||||||
|
slug: article.id,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
const Article = async ({params}: { params: Promise<{ slug: string }> }) => {
|
const Article = async ({params}: { params: Promise<{ slug: string }> }) => {
|
||||||
const {slug} = await params;
|
const {slug} = await params;
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import type {ArticleItem} from "@/types";
|
||||||
|
|
||||||
const articlesDirectory = path.join(process.cwd(), "articles");
|
const articlesDirectory = path.join(process.cwd(), "articles");
|
||||||
|
|
||||||
const getSortedArticles = (): ArticleItem[] => {
|
export const getSortedArticles = (): ArticleItem[] => {
|
||||||
const fileNames = fs.readdirSync(articlesDirectory);
|
const fileNames = fs.readdirSync(articlesDirectory);
|
||||||
|
|
||||||
const allArticlesData = fileNames.map((fileName) => {
|
const allArticlesData = fileNames.map((fileName) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue