-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy path[page].tsx
More file actions
37 lines (32 loc) · 903 Bytes
/
[page].tsx
File metadata and controls
37 lines (32 loc) · 903 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import React from "react";
import { loadBlogIndex } from "@helpers/blog";
import BlogIndex from "@components/BlogIndex";
export default function BlogPageIndex({
posts,
page,
pageCount,
}: Awaited<ReturnType<typeof getStaticProps>>["props"]) {
return <BlogIndex posts={posts} page={page} pageCount={pageCount} />;
}
export const getStaticProps = async ({
params,
}: {
params: { page: string };
}) => {
const { page: pageString } = params;
const page = Number(pageString);
const { posts, pageCount } = await loadBlogIndex("src/blog", page);
return {
props: { posts, page, pageCount },
};
};
export const getStaticPaths = async () => {
const { pageCount } = await loadBlogIndex("src/blog", 1);
// TODO: support localization
return {
paths: Array.from({ length: pageCount }).map((_, i) => ({
params: { page: `${i + 1}` },
})),
fallback: false,
};
};