mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-13 23:16:47 +00:00
52 lines
1.4 KiB
JavaScript
52 lines
1.4 KiB
JavaScript
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 })
|
|
const { siteInfo } = props
|
|
props.posts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published')
|
|
const meta = {
|
|
title: `${siteInfo?.title} | ${siteInfo?.description}`,
|
|
description: siteInfo?.description,
|
|
image: siteInfo?.pageCover,
|
|
slug: '',
|
|
type: 'website'
|
|
}
|
|
// 处理分页
|
|
if (BLOG.POST_LIST_STYLE === 'scroll') {
|
|
// 滚动列表默认给前端返回所有数据
|
|
} else if (BLOG.POST_LIST_STYLE === 'page') {
|
|
props.posts = props.posts?.slice(0, BLOG.POSTS_PER_PAGE)
|
|
}
|
|
|
|
// 预览文章内容
|
|
if (BLOG.POST_LIST_PREVIEW === 'true') {
|
|
for (const i in props.posts) {
|
|
const post = props.posts[i]
|
|
if (post.password && post.password !== '') {
|
|
continue
|
|
}
|
|
post.blockMap = await getPostBlocks(post.id, 'slug', BLOG.POST_PREVIEW_LINES)
|
|
}
|
|
}
|
|
|
|
return {
|
|
props: {
|
|
meta,
|
|
...props
|
|
},
|
|
revalidate: 5
|
|
}
|
|
}
|
|
|
|
export default Index
|