mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-31 23:16:54 +00:00
完成单页初版本开发
This commit is contained in:
@@ -35,7 +35,6 @@ export async function getStaticPaths () {
|
||||
export async function getStaticProps ({ params: { slug } }) {
|
||||
const from = `slug-props-${slug}`
|
||||
const { allPosts, categories, tags, postCount, latestPosts, customNav } = await getGlobalNotionData({ from, pageType: ['Page'] })
|
||||
|
||||
const post = allPosts.find(p => p.slug === slug)
|
||||
if (!post) {
|
||||
return { props: {}, revalidate: 1 }
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
import { getPostBlocks } from '@/lib/notion'
|
||||
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
|
||||
import Custom404 from '@/pages/404'
|
||||
import React from 'react'
|
||||
import { LayoutSlug } from '@/themes'
|
||||
|
||||
/**
|
||||
* 关于页面,默认取notion中slug为about的文章
|
||||
* @param {*} props
|
||||
* @returns
|
||||
*/
|
||||
const About = (props) => {
|
||||
if (!props.post) {
|
||||
return <Custom404 {...props} />
|
||||
}
|
||||
return <LayoutSlug {...props} />
|
||||
}
|
||||
|
||||
export async function getStaticProps () {
|
||||
const from = 'about-props'
|
||||
const {
|
||||
allPosts,
|
||||
categories,
|
||||
tags,
|
||||
postCount,
|
||||
latestPosts
|
||||
} = await getGlobalNotionData({
|
||||
from,
|
||||
pageType: ['Page']
|
||||
})
|
||||
const post = allPosts.find(p => p.slug === 'about')
|
||||
|
||||
if (!post) {
|
||||
return {
|
||||
props: {},
|
||||
revalidate: 1
|
||||
}
|
||||
}
|
||||
|
||||
post.blockMap = await getPostBlocks(post.id, 'slug')
|
||||
|
||||
const index = allPosts.indexOf(post)
|
||||
const prev = allPosts.slice(index - 1, index)[0] ?? allPosts.slice(-1)[0]
|
||||
const next = allPosts.slice(index + 1, index + 2)[0] ?? allPosts[0]
|
||||
|
||||
return {
|
||||
props: {
|
||||
post,
|
||||
tags,
|
||||
prev,
|
||||
next,
|
||||
categories,
|
||||
postCount,
|
||||
latestPosts
|
||||
},
|
||||
revalidate: 1
|
||||
}
|
||||
}
|
||||
|
||||
export default About
|
||||
@@ -35,7 +35,7 @@ export async function getStaticPaths () {
|
||||
export async function getStaticProps ({ params: { slug } }) {
|
||||
const from = `slug-props-${slug}`
|
||||
const { customNav, allPosts, categories, tags, postCount, latestPosts } =
|
||||
await getGlobalNotionData({ from })
|
||||
await getGlobalNotionData({ from, pageType: ['Post'] })
|
||||
|
||||
const post = allPosts.find(p => p.slug === slug)
|
||||
|
||||
@@ -45,10 +45,9 @@ export async function getStaticProps ({ params: { slug } }) {
|
||||
|
||||
post.blockMap = await getPostBlocks(post.id, 'slug')
|
||||
|
||||
const posts = allPosts.filter(post => post?.type?.[0] === 'Post')
|
||||
const index = posts.indexOf(post)
|
||||
const prev = posts.slice(index - 1, index)[0] ?? posts.slice(-1)[0]
|
||||
const next = posts.slice(index + 1, index + 2)[0] ?? posts[0]
|
||||
const index = allPosts.indexOf(post)
|
||||
const prev = allPosts.slice(index - 1, index)[0] ?? allPosts.slice(-1)[0]
|
||||
const next = allPosts.slice(index + 1, index + 2)[0] ?? allPosts[0]
|
||||
|
||||
const recommendPosts = getRecommendPost(post, allPosts)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user