mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-02 23:16:51 +00:00
Merge branch 'main' into fix-article-cover
# Conflicts: # lib/notion/getAllPosts.js # lib/notion/getNotionData.js
This commit is contained in:
@@ -1,2 +1,2 @@
|
|||||||
# 环境变量 @see https://www.nextjs.cn/docs/basic-features/environment-variables
|
# 环境变量 @see https://www.nextjs.cn/docs/basic-features/environment-variables
|
||||||
NEXT_PUBLIC_VERSION=3.3.5
|
NEXT_PUBLIC_VERSION=3.3.6
|
||||||
@@ -6,7 +6,7 @@ const CommonHead = ({ meta, children }) => {
|
|||||||
let image
|
let image
|
||||||
if (meta) {
|
if (meta) {
|
||||||
url = `${url}/${meta.slug}`
|
url = `${url}/${meta.slug}`
|
||||||
image = meta.image || ''
|
image = meta.image || '/bg_image.jpg'
|
||||||
}
|
}
|
||||||
const title = meta?.title || BLOG.TITLE
|
const title = meta?.title || BLOG.TITLE
|
||||||
const description = meta?.description || BLOG.DESCRIPTION
|
const description = meta?.description || BLOG.DESCRIPTION
|
||||||
|
|||||||
@@ -1,3 +1,2 @@
|
|||||||
export { getAllPosts } from './notion/getAllPosts'
|
|
||||||
export { getAllTags } from './notion/getAllTags'
|
export { getAllTags } from './notion/getAllTags'
|
||||||
export { getPostBlocks } from './notion/getPostBlocks'
|
export { getPostBlocks } from './notion/getPostBlocks'
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import { idToUuid } from 'notion-utils'
|
|||||||
import { defaultMapImageUrl } from 'react-notion-x'
|
import { defaultMapImageUrl } from 'react-notion-x'
|
||||||
import { deepClone, isIterable } from '../utils'
|
import { deepClone, isIterable } from '../utils'
|
||||||
import getAllPageIds from './getAllPageIds'
|
import getAllPageIds from './getAllPageIds'
|
||||||
import { getAllPosts } from './getAllPosts'
|
|
||||||
import { getAllTags } from './getAllTags'
|
import { getAllTags } from './getAllTags'
|
||||||
import getPageProperties from './getPageProperties'
|
import getPageProperties from './getPageProperties'
|
||||||
|
|
||||||
@@ -81,14 +80,16 @@ export async function getNotionPageData({ pageId, from }) {
|
|||||||
* @param notionPageData
|
* @param notionPageData
|
||||||
* @returns {Promise<[]|*[]>}
|
* @returns {Promise<[]|*[]>}
|
||||||
*/
|
*/
|
||||||
function getCustomNav({ allPage }) {
|
function getCustomNav({ allPages }) {
|
||||||
const customNav = []
|
const customNav = []
|
||||||
if (allPage && allPage.length > 0) {
|
if (allPages && allPages.length > 0) {
|
||||||
allPage.forEach(p => {
|
allPages.forEach(p => {
|
||||||
if (p?.slug?.indexOf('http') === 0) {
|
if (p?.status?.[0] === 'Published') {
|
||||||
customNav.push({ icon: p.icon || null, name: p.title, to: p.slug, show: true })
|
if (p?.slug?.indexOf('http') === 0) {
|
||||||
} else {
|
customNav.push({ icon: p.icon || null, name: p.title, to: p.slug, show: true })
|
||||||
customNav.push({ icon: p.icon || null, name: p.title, to: '/' + p.slug, show: true })
|
} else {
|
||||||
|
customNav.push({ icon: p.icon || null, name: p.title, to: '/' + p.slug, show: true })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -235,11 +236,11 @@ async function getPageRecordMapByNotionAPI({ pageId, from }) {
|
|||||||
const tagOptions = getTagOptions(schema)
|
const tagOptions = getTagOptions(schema)
|
||||||
const categoryOptions = getCategoryOptions(schema)
|
const categoryOptions = getCategoryOptions(schema)
|
||||||
const viewIds = rawMetadata?.view_ids
|
const viewIds = rawMetadata?.view_ids
|
||||||
const data = []
|
const collectionData = []
|
||||||
const pageIds = getAllPageIds(collectionQuery, collectionId, collectionView, viewIds)
|
const pageIds = getAllPageIds(collectionQuery, collectionId, collectionView, viewIds)
|
||||||
const siteInfo = getBlogInfo({ collection, block })
|
const siteInfo = getBlogInfo({ collection, block })
|
||||||
if (pageIds?.length === 0) {
|
if (pageIds?.length === 0) {
|
||||||
console.error('获取到的文章列表为空,请检查notion模板', collectionQuery, collection, pageRecordMap)
|
console.error('获取到的文章列表为空,请检查notion模板', collectionQuery, collection, collectionView, viewIds, pageRecordMap)
|
||||||
}
|
}
|
||||||
for (let i = 0; i < pageIds.length; i++) {
|
for (let i = 0; i < pageIds.length; i++) {
|
||||||
const id = pageIds[i]
|
const id = pageIds[i]
|
||||||
@@ -247,20 +248,30 @@ async function getPageRecordMapByNotionAPI({ pageId, from }) {
|
|||||||
if (!value) {
|
if (!value) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
collectionData.push(properties)
|
||||||
const properties = (await getPageProperties(id, block, schema, null, tagOptions, siteInfo)) || null
|
const properties = (await getPageProperties(id, block, schema, null, tagOptions, siteInfo)) || null
|
||||||
if (properties) {
|
if (properties) {
|
||||||
data.push(properties)
|
data.push(properties)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const allPage = data.filter(post => {
|
const allPages = collectionData.filter(post => {
|
||||||
return post.title && post?.status?.[0] === 'Published' && ['Page'].indexOf(post?.type?.[0]) > -1
|
return post.title && ['Page'].indexOf(post?.type?.[0]) > -1 && (post?.status?.[0] === 'Published' || post?.status?.[0] === 'Invisible')
|
||||||
})
|
})
|
||||||
const allPosts = data.filter(post => {
|
const allPosts = collectionData.filter(post => {
|
||||||
return post.title && post?.status?.[0] === 'Published' && ['Post'].indexOf(post?.type?.[0]) > -1
|
return post.title && ['Post'].indexOf(post?.type?.[0]) > -1 && post?.status?.[0] === 'Published'
|
||||||
})
|
})
|
||||||
|
|
||||||
const customNav = getCustomNav({ allPage })
|
// Sort by date
|
||||||
|
if (BLOG.POSTS_SORT_BY === 'date') {
|
||||||
|
allPosts.sort((a, b) => {
|
||||||
|
const dateA = new Date(a?.date?.start_date || a.createdTime)
|
||||||
|
const dateB = new Date(b?.date?.start_date || b.createdTime)
|
||||||
|
return dateB - dateA
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const customNav = getCustomNav({ allPages })
|
||||||
const postCount = allPosts?.length || 0
|
const postCount = allPosts?.length || 0
|
||||||
const categories = getAllCategories({ allPosts, categoryOptions, sliceCount: BLOG.PREVIEW_CATEGORY_COUNT })
|
const categories = getAllCategories({ allPosts, categoryOptions, sliceCount: BLOG.PREVIEW_CATEGORY_COUNT })
|
||||||
const tags = getAllTags({ allPosts, tagOptions, sliceCount: BLOG.PREVIEW_TAG_COUNT })
|
const tags = getAllTags({ allPosts, tagOptions, sliceCount: BLOG.PREVIEW_TAG_COUNT })
|
||||||
@@ -268,6 +279,8 @@ async function getPageRecordMapByNotionAPI({ pageId, from }) {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
siteInfo,
|
siteInfo,
|
||||||
|
allPages,
|
||||||
|
allPosts,
|
||||||
collection,
|
collection,
|
||||||
collectionQuery,
|
collectionQuery,
|
||||||
collectionId,
|
collectionId,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "notion-next",
|
"name": "notion-next",
|
||||||
"version": "3.3.5",
|
"version": "3.3.6",
|
||||||
"homepage": "https://github.com/tangly1024/NotionNext.git",
|
"homepage": "https://github.com/tangly1024/NotionNext.git",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ import { useGlobal } from '@/lib/global'
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
const NoFound = props => {
|
const NoFound = props => {
|
||||||
const { theme } = useGlobal()
|
const { theme, siteInfo } = useGlobal()
|
||||||
const ThemeComponents = ThemeMap[theme]
|
const ThemeComponents = ThemeMap[theme]
|
||||||
const meta = { title: `${props?.siteInfo?.title} | 页面找不到啦` }
|
const meta = { title: `${props?.siteInfo?.title} | 页面找不到啦`, image: siteInfo?.pageCover }
|
||||||
return <ThemeComponents.Layout404 {...props} meta={meta}/>
|
return <ThemeComponents.Layout404 {...props} meta={meta}/>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -80,12 +80,10 @@ export async function getStaticPaths() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const from = 'slug-paths'
|
const from = 'slug-paths'
|
||||||
const { allPosts } = await getGlobalNotionData({ from, pageType: ['Page'] })
|
const { allPages } = await getGlobalNotionData({ from, pageType: ['Page'] })
|
||||||
const filterPosts =
|
|
||||||
allPosts?.filter(e => e?.slug?.indexOf('http') !== 0) || []
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
paths: filterPosts.map(row => ({ params: { slug: row.slug } })),
|
paths: allPages.map(row => ({ params: { slug: row.slug } })),
|
||||||
fallback: true
|
fallback: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,19 +91,19 @@ export async function getStaticPaths() {
|
|||||||
export async function getStaticProps({ params: { slug } }) {
|
export async function getStaticProps({ params: { slug } }) {
|
||||||
const from = `slug-props-${slug}`
|
const from = `slug-props-${slug}`
|
||||||
const props = await getGlobalNotionData({ from, pageType: ['Page'] })
|
const props = await getGlobalNotionData({ from, pageType: ['Page'] })
|
||||||
const { allPosts } = props
|
const { allPages } = props
|
||||||
const post = allPosts.find(p => p.slug === slug)
|
const page = allPages?.find(p => p.slug === slug)
|
||||||
if (!post) {
|
if (!page) {
|
||||||
return { props: {}, revalidate: 1 }
|
return { props: {}, revalidate: 1 }
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
post.blockMap = await getPostBlocks(post.id, 'slug')
|
page.blockMap = await getPostBlocks(page.id, 'slug')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取文章详情失败', error)
|
console.error('获取文章详情失败', error)
|
||||||
}
|
}
|
||||||
|
|
||||||
props.post = post
|
props.post = page
|
||||||
|
|
||||||
return {
|
return {
|
||||||
props,
|
props,
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ const ArchiveIndex = props => {
|
|||||||
const meta = {
|
const meta = {
|
||||||
title: `${locale.NAV.ARCHIVE} | ${siteInfo?.title}`,
|
title: `${locale.NAV.ARCHIVE} | ${siteInfo?.title}`,
|
||||||
description: siteInfo?.description,
|
description: siteInfo?.description,
|
||||||
|
image: siteInfo?.pageCover,
|
||||||
slug: 'archive',
|
slug: 'archive',
|
||||||
type: 'website'
|
type: 'website'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import { useRouter } from 'next/router'
|
|||||||
const Slug = props => {
|
const Slug = props => {
|
||||||
const { theme, changeLoadingState } = useGlobal()
|
const { theme, changeLoadingState } = useGlobal()
|
||||||
const ThemeComponents = ThemeMap[theme]
|
const ThemeComponents = ThemeMap[theme]
|
||||||
const { post } = props
|
const { post, siteInfo } = props
|
||||||
|
|
||||||
if (!post) {
|
if (!post) {
|
||||||
changeLoadingState(true)
|
changeLoadingState(true)
|
||||||
@@ -30,7 +30,7 @@ const Slug = props => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 10000)
|
}, 10000)
|
||||||
const meta = { title: `${props?.siteInfo?.title || BLOG.TITLE} | loading` }
|
const meta = { title: `${props?.siteInfo?.title || BLOG.TITLE} | loading`, image: siteInfo?.pageCover }
|
||||||
return <ThemeComponents.LayoutSlug {...props} showArticleInfo={true} meta={meta} />
|
return <ThemeComponents.LayoutSlug {...props} showArticleInfo={true} meta={meta} />
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,7 +58,6 @@ const Slug = props => {
|
|||||||
|
|
||||||
props = { ...props, lock, setLock, validPassword }
|
props = { ...props, lock, setLock, validPassword }
|
||||||
|
|
||||||
const { siteInfo } = props
|
|
||||||
const meta = {
|
const meta = {
|
||||||
title: `${post?.title} | ${siteInfo?.title}`,
|
title: `${post?.title} | ${siteInfo?.title}`,
|
||||||
description: post?.summary,
|
description: post?.summary,
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ export default function Category(props) {
|
|||||||
}`,
|
}`,
|
||||||
description: siteInfo?.description,
|
description: siteInfo?.description,
|
||||||
slug: 'category/' + props.category,
|
slug: 'category/' + props.category,
|
||||||
|
image: siteInfo?.pageCover,
|
||||||
type: 'website'
|
type: 'website'
|
||||||
}
|
}
|
||||||
return <ThemeComponents.LayoutCategory {...props} meta={meta} />
|
return <ThemeComponents.LayoutCategory {...props} meta={meta} />
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ export default function Category(props) {
|
|||||||
const meta = {
|
const meta = {
|
||||||
title: `${locale.COMMON.CATEGORY} | ${siteInfo?.title}`,
|
title: `${locale.COMMON.CATEGORY} | ${siteInfo?.title}`,
|
||||||
description: siteInfo?.description,
|
description: siteInfo?.description,
|
||||||
|
image: siteInfo?.pageCover,
|
||||||
slug: 'category',
|
slug: 'category',
|
||||||
type: 'website'
|
type: 'website'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ const Page = props => {
|
|||||||
const meta = {
|
const meta = {
|
||||||
title: `${props.page} | Page | ${siteInfo?.title}`,
|
title: `${props.page} | Page | ${siteInfo?.title}`,
|
||||||
description: siteInfo?.description,
|
description: siteInfo?.description,
|
||||||
|
image: siteInfo?.pageCover,
|
||||||
slug: 'page/' + props.page,
|
slug: 'page/' + props.page,
|
||||||
type: 'website'
|
type: 'website'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ const Index = props => {
|
|||||||
const meta = {
|
const meta = {
|
||||||
title: `${keyword || ''}${keyword ? ' | ' : ''}${locale.NAV.SEARCH} | ${siteInfo?.title}`,
|
title: `${keyword || ''}${keyword ? ' | ' : ''}${locale.NAV.SEARCH} | ${siteInfo?.title}`,
|
||||||
description: siteInfo?.title,
|
description: siteInfo?.title,
|
||||||
|
image: siteInfo?.pageCover,
|
||||||
slug: 'search/' + (keyword || ''),
|
slug: 'search/' + (keyword || ''),
|
||||||
type: 'website'
|
type: 'website'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ const Search = props => {
|
|||||||
siteInfo?.title
|
siteInfo?.title
|
||||||
}`,
|
}`,
|
||||||
description: siteInfo?.description,
|
description: siteInfo?.description,
|
||||||
|
image: siteInfo?.pageCover,
|
||||||
slug: 'search',
|
slug: 'search',
|
||||||
type: 'website'
|
type: 'website'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ const Tag = props => {
|
|||||||
const meta = {
|
const meta = {
|
||||||
title: `${tag} | ${locale.COMMON.TAGS} | ${siteInfo?.title}`,
|
title: `${tag} | ${locale.COMMON.TAGS} | ${siteInfo?.title}`,
|
||||||
description: siteInfo?.description,
|
description: siteInfo?.description,
|
||||||
|
image: siteInfo?.pageCover,
|
||||||
slug: 'tag/' + tag,
|
slug: 'tag/' + tag,
|
||||||
type: 'website'
|
type: 'website'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ const TagIndex = props => {
|
|||||||
const meta = {
|
const meta = {
|
||||||
title: `${locale.COMMON.TAGS} | ${siteInfo?.title}`,
|
title: `${locale.COMMON.TAGS} | ${siteInfo?.title}`,
|
||||||
description: siteInfo?.description,
|
description: siteInfo?.description,
|
||||||
|
image: siteInfo?.pageCover,
|
||||||
slug: 'tag',
|
slug: 'tag',
|
||||||
type: 'website'
|
type: 'website'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,13 +37,16 @@ export default function ArticleDetail(props) {
|
|||||||
|
|
||||||
<section className="flex-wrap flex mt-2 text-gray-400 dark:text-gray-400 font-light leading-8">
|
<section className="flex-wrap flex mt-2 text-gray-400 dark:text-gray-400 font-light leading-8">
|
||||||
<div>
|
<div>
|
||||||
<Link href={`/category/${post.category}`} passHref>
|
|
||||||
<a className="cursor-pointer text-md mr-2 hover:text-black dark:hover:text-white border-b dark:border-gray-500 border-dashed">
|
{post?.category && (<>
|
||||||
<i className="mr-1 fas fa-folder-open" />
|
<Link href={`/category/${post.category}`} passHref>
|
||||||
{post.category}
|
<a className="cursor-pointer text-md mr-2 hover:text-black dark:hover:text-white border-b dark:border-gray-500 border-dashed">
|
||||||
</a>
|
<i className="mr-1 fas fa-folder-open" />
|
||||||
</Link>
|
{post.category}
|
||||||
<span className='mr-2'>|</span>
|
</a>
|
||||||
|
</Link>
|
||||||
|
<span className='mr-2'>|</span>
|
||||||
|
</>)}
|
||||||
|
|
||||||
{post?.type[0] !== 'Page' && (<>
|
{post?.type[0] !== 'Page' && (<>
|
||||||
<Link
|
<Link
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ const LayoutBase = props => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="bg-hexo-background-gray dark:bg-black">
|
<div className="bg-hexo-background-gray dark:bg-black">
|
||||||
<CommonHead meta={meta} />
|
<CommonHead meta={meta} siteInfo={siteInfo}/>
|
||||||
|
|
||||||
<TopNav {...props} />
|
<TopNav {...props} />
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user