forked from tangly1024/NotionNext
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
62 lines (58 loc) · 1.51 KB
/
index.js
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import BLOG from '@/blog.config'
import { getPostBlocks } from '@/lib/notion'
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
import * as ThemeMap from '@/themes'
import { useGlobal } from '@/lib/global'
const Index = props => {
const { theme } = useGlobal()
const ThemeComponents = ThemeMap[theme]
return <ThemeComponents.LayoutIndex {...props} />
}
export async function getStaticProps() {
const from = 'index'
const props = await getGlobalNotionData({ from, pageType: ['Post'] })
const { allPosts, siteInfo } = props
const meta = {
title: `${siteInfo?.title} | ${siteInfo?.description}`,
description: siteInfo?.description,
image: siteInfo?.pageCover,
slug: '',
type: 'website'
}
// 处理分页
const page = 1
let postsToShow
if (BLOG.POST_LIST_STYLE !== 'page') {
postsToShow = Array.from(allPosts)
} else {
postsToShow = allPosts?.slice(
BLOG.POSTS_PER_PAGE * (page - 1),
BLOG.POSTS_PER_PAGE * page
)
if (BLOG.POST_LIST_PREVIEW === 'true') {
for (const i in postsToShow) {
const post = postsToShow[i]
if (post.password && post.password !== '') {
continue
}
const blockMap = await getPostBlocks(
post.id,
'slug',
BLOG.POST_PREVIEW_LINES
)
if (blockMap) {
post.blockMap = blockMap
}
}
}
}
props.posts = postsToShow
return {
props: {
meta,
...props
},
revalidate: 5
}
}
export default Index