|
import BLOG from '@/blog.config' |
|
import { getPostBlocks } from '@/lib/notion' |
|
import { getGlobalData } from '@/lib/notion/getNotionData' |
|
import { generateRss } from '@/lib/rss' |
|
import { generateRobotsTxt } from '@/lib/robots.txt' |
|
import { getLayoutByTheme } from '@/themes/theme' |
|
import { siteConfig } from '@/lib/config' |
|
import { useRouter } from 'next/router' |
|
|
|
|
|
|
|
|
|
|
|
|
|
const Index = props => { |
|
|
|
const Layout = getLayoutByTheme({ theme: siteConfig('THEME'), router: useRouter() }) |
|
return <Layout {...props} /> |
|
} |
|
|
|
|
|
|
|
|
|
|
|
export async function getStaticProps() { |
|
const from = 'index' |
|
const props = await getGlobalData({ from }) |
|
|
|
props.posts = props.allPages?.filter(page => page.type === 'Post' && page.status === 'Published') |
|
|
|
|
|
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) |
|
} |
|
} |
|
|
|
|
|
generateRobotsTxt() |
|
|
|
if (JSON.parse(BLOG.ENABLE_RSS)) { |
|
generateRss(props?.latestPosts || []) |
|
} |
|
|
|
|
|
|
|
delete props.allPages |
|
|
|
return { |
|
props, |
|
revalidate: parseInt(BLOG.NEXT_REVALIDATE_SECOND) |
|
} |
|
} |
|
|
|
export default Index |
|
|