mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 07:26:52 +00:00
完成单页初版本开发
This commit is contained in:
@@ -36,7 +36,6 @@ export async function getAllPosts ({ notionPageData, from, pageType }) {
|
||||
properties.fullWidth = pageBlock[id].value?.format?.page_full_width ?? false
|
||||
properties.page_cover = getPostCover(id, pageBlock) ?? null
|
||||
properties.content = pageBlock[id].value?.content ?? []
|
||||
properties.icon = pageBlock[id].value?.icon ?? null
|
||||
properties.tagItems = properties?.tags?.map(tag => {
|
||||
return { name: tag, color: tagOptions.find(t => t.value === tag)?.color || 'gray' }
|
||||
}) || []
|
||||
@@ -74,3 +73,19 @@ function getPostCover (id, block) {
|
||||
if (pageCover.startsWith('http')) return defaultMapImageUrl(pageCover, block[id].value)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取博文总数
|
||||
* @param {*} param0
|
||||
* @returns
|
||||
*/
|
||||
export async function getAllPostCount ({ notionPageData, from }) {
|
||||
if (!notionPageData) {
|
||||
notionPageData = await getNotionPageData({ from })
|
||||
}
|
||||
if (!notionPageData) {
|
||||
return []
|
||||
}
|
||||
const allPosts = await getAllPosts({ notionPageData, from, pageType: ['Post'] })
|
||||
return allPosts?.length || 0
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import { getDataFromCache, setDataToCache } from '@/lib/cache/cache_manager'
|
||||
import { getPostBlocks } from '@/lib/notion/getPostBlocks'
|
||||
import { idToUuid } from 'notion-utils'
|
||||
import { getAllCategories } from './getAllCategories'
|
||||
import { getAllPosts } from './getAllPosts'
|
||||
import { getAllPosts, getAllPostCount } from './getAllPosts'
|
||||
import { getAllTags } from './getAllTags'
|
||||
|
||||
/**
|
||||
@@ -33,8 +33,7 @@ export async function getGlobalNotionData ({
|
||||
const notionPageData = await getNotionPageData({ pageId, from })
|
||||
const tagOptions = notionPageData.tagOptions
|
||||
const allPosts = await getAllPosts({ notionPageData, from, pageType })
|
||||
const postCount = allPosts?.filter(post => post?.status?.[0] === 'Published' && (post?.type?.[0] === 'Post')
|
||||
)?.length
|
||||
const postCount = await getAllPostCount({ notionPageData, from })
|
||||
const customNav = await getCustomNav({ notionPageData })
|
||||
const categories = await getAllCategories(allPosts)
|
||||
const tags = await getAllTags({ allPosts, tagOptions, sliceCount: tagsCount })
|
||||
@@ -89,8 +88,13 @@ async function getCustomNav ({ notionPageData }) {
|
||||
return []
|
||||
}
|
||||
const allPage = await getAllPosts({ notionPageData, from: 'custom-nav', pageType: ['Page'] })
|
||||
console.log(allPage)
|
||||
return [{ icon: 'fas fa-file-alt', name: '简历', to: '/' + 'resume', show: true }]
|
||||
const customNav = []
|
||||
if (allPage && allPage.length > 0) {
|
||||
allPage.forEach(p => {
|
||||
customNav.push({ icon: p.icon, name: p.title, to: '/' + p.slug, show: true })
|
||||
})
|
||||
}
|
||||
return customNav
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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