use Next.js
This commit is contained in:
1 parent
cf94c66807
commit
20a00d5ab3
34 files changed
+7117
-1
No files matched your search
@@ -0,0 +1,52 @@
|
||||
import PostQuery from '~/components/PostQuery'
|
||||
import { doSearch } from '~/server'
|
||||
import { IPost, dbPost, initDatabase } from '~/server/db'
|
||||
import { GetStaticPaths, GetStaticProps } from 'next'
|
||||
|
||||
const BlogPagePaged = ({
|
||||
count,
|
||||
result
|
||||
}: {
|
||||
count: number
|
||||
result: IPost[]
|
||||
}) => {
|
||||
return (
|
||||
<PostQuery
|
||||
defaults={{
|
||||
posts: result,
|
||||
count
|
||||
}}
|
||||
></PostQuery>
|
||||
)
|
||||
}
|
||||
|
||||
export default BlogPagePaged
|
||||
|
||||
export const getStaticPaths: GetStaticPaths = async () => {
|
||||
await initDatabase()
|
||||
|
||||
return {
|
||||
paths: Array(
|
||||
Math.ceil(
|
||||
dbPost.find({
|
||||
date: { $exists: true } as any
|
||||
}).length / 5
|
||||
) - 1
|
||||
)
|
||||
.fill(null)
|
||||
.map((_, i) => ({
|
||||
params: {
|
||||
page: (i + 2).toString()
|
||||
}
|
||||
})),
|
||||
fallback: false
|
||||
}
|
||||
}
|
||||
|
||||
export const getStaticProps: GetStaticProps = async (ctx) => {
|
||||
return {
|
||||
props: await doSearch({
|
||||
page: parseInt(ctx.params.page as string)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user