From 1e0ef1aee9e19472f2b4bb4b1bb878f1fd084e95 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Mon, 16 May 2022 14:45:41 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E8=8F=9C=E5=8D=95Page=E5=8F=AF=E9=9A=90?= =?UTF-8?q?=E8=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/notion/getNotionData.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/notion/getNotionData.js b/lib/notion/getNotionData.js index 076a56c3..feb7e786 100644 --- a/lib/notion/getNotionData.js +++ b/lib/notion/getNotionData.js @@ -87,10 +87,12 @@ function getCustomNav({ allPage }) { const customNav = [] if (allPage && allPage.length > 0) { allPage.forEach(p => { - if (p?.slug?.indexOf('http') === 0) { - 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 }) + if (p?.status?.[0] === 'Published') { + if (p?.slug?.indexOf('http') === 0) { + 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 }) + } } }) } @@ -253,7 +255,7 @@ async function getPageRecordMapByNotionAPI({ pageId, from }) { } const allPage = data.filter(post => { - return post.title && post?.status?.[0] === 'Published' && ['Page'].indexOf(post?.type?.[0]) > -1 + return post.title && (post?.status?.[0] === 'Published' || post?.status?.[0] === 'Invisible') && ['Page'].indexOf(post?.type?.[0]) > -1 }) const allPosts = data.filter(post => { return post.title && post?.status?.[0] === 'Published' && ['Post'].indexOf(post?.type?.[0]) > -1 From b453df8d5dd689b33e2f2d080a70fd46c16dfe75 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Mon, 16 May 2022 15:27:08 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E8=AE=BF=E9=97=AE=20=E9=9A=90=E8=97=8F?= =?UTF-8?q?=E5=8D=95=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/notion/getAllPosts.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/notion/getAllPosts.js b/lib/notion/getAllPosts.js index c853ffdd..c7d14684 100644 --- a/lib/notion/getAllPosts.js +++ b/lib/notion/getAllPosts.js @@ -34,7 +34,12 @@ export async function getAllPosts({ notionPageData, from, pageType }) { // remove all the the items doesn't meet requirements const posts = data.filter(post => { - return post.title && post?.status?.[0] === 'Published' && pageType.indexOf(post?.type?.[0]) > -1 + if (pageType === 'Post') { + return post.title && post?.status?.[0] === 'Published' && pageType.indexOf(post?.type?.[0]) > -1 + } else { + // 隐藏单页 + return post.title && (post?.status?.[0] === 'Published' || post?.status?.[0] === 'Invisible') && pageType.indexOf(post?.type?.[0]) > -1 + } }) if (!posts || posts.length === 0) { From 598d8d0b5be756e52bb2b167b9846f3b739100ff Mon Sep 17 00:00:00 2001 From: tlyong1992 Date: Wed, 18 May 2022 13:46:08 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E5=B0=81=E8=A3=85=20allPages?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/notion.js | 1 - lib/notion/getAllPosts.js | 59 ------------------------------------- lib/notion/getNotionData.js | 36 +++++++++++++--------- pages/[slug].js | 16 +++++----- 4 files changed, 29 insertions(+), 83 deletions(-) delete mode 100644 lib/notion/getAllPosts.js diff --git a/lib/notion.js b/lib/notion.js index 51c02180..0042487f 100644 --- a/lib/notion.js +++ b/lib/notion.js @@ -1,3 +1,2 @@ -export { getAllPosts } from './notion/getAllPosts' export { getAllTags } from './notion/getAllTags' export { getPostBlocks } from './notion/getPostBlocks' diff --git a/lib/notion/getAllPosts.js b/lib/notion/getAllPosts.js deleted file mode 100644 index c7d14684..00000000 --- a/lib/notion/getAllPosts.js +++ /dev/null @@ -1,59 +0,0 @@ -import BLOG from '@/blog.config' -import getAllPageIds from './getAllPageIds' -import getPageProperties from './getPageProperties' -import { getNotionPageData } from '@/lib/notion/getNotionData' -import { delCacheData } from '@/lib/cache/cache_manager' - -/** - * 获取所有文章列表 - * @param notionPageData - * @param from - * @param pageType 页面类型数组 ['Post','Page'] - * @returns {Promise<*[]>} - */ -export async function getAllPosts({ notionPageData, from, pageType }) { - if (!notionPageData) { - notionPageData = await getNotionPageData({ from }) - } - if (!notionPageData) { - return [] - } - - const { block, schema, tagOptions, collectionQuery, collectionId, collectionView, viewIds } = notionPageData - const data = [] - const pageIds = getAllPageIds(collectionQuery, collectionId, collectionView, viewIds) - for (let i = 0; i < pageIds.length; i++) { - const id = pageIds[i] - const value = block[id]?.value - if (!value) { - continue - } - const properties = (await getPageProperties(id, block, schema, tagOptions)) || null - data.push(properties) - } - - // remove all the the items doesn't meet requirements - const posts = data.filter(post => { - if (pageType === 'Post') { - return post.title && post?.status?.[0] === 'Published' && pageType.indexOf(post?.type?.[0]) > -1 - } else { - // 隐藏单页 - return post.title && (post?.status?.[0] === 'Published' || post?.status?.[0] === 'Invisible') && pageType.indexOf(post?.type?.[0]) > -1 - } - }) - - if (!posts || posts.length === 0) { - const cacheKey = 'page_block_' + BLOG.NOTION_PAGE_ID - await delCacheData(cacheKey) - } - - // Sort by date - if (BLOG.POSTS_SORT_BY === 'date') { - posts.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 - }) - } - return posts -} diff --git a/lib/notion/getNotionData.js b/lib/notion/getNotionData.js index feb7e786..f856c0ef 100644 --- a/lib/notion/getNotionData.js +++ b/lib/notion/getNotionData.js @@ -5,7 +5,6 @@ import { idToUuid } from 'notion-utils' import { defaultMapImageUrl } from 'react-notion-x' import { deepClone, isIterable } from '../utils' import getAllPageIds from './getAllPageIds' -import { getAllPosts } from './getAllPosts' import { getAllTags } from './getAllTags' import getPageProperties from './getPageProperties' @@ -29,8 +28,6 @@ export async function getGlobalNotionData({ const notionPageData = deepClone(await getNotionPageData({ pageId, from })) notionPageData.siteInfo = getBlogInfo({ collection: notionPageData?.collection, block: notionPageData?.block }) - // 获取文章列表 - notionPageData.allPosts = await getAllPosts({ notionPageData, from, pageType }) delete notionPageData.block delete notionPageData.collection delete notionPageData.collectionQuery @@ -83,10 +80,10 @@ export async function getNotionPageData({ pageId, from }) { * @param notionPageData * @returns {Promise<[]|*[]>} */ -function getCustomNav({ allPage }) { +function getCustomNav({ allPages }) { const customNav = [] - if (allPage && allPage.length > 0) { - allPage.forEach(p => { + if (allPages && allPages.length > 0) { + allPages.forEach(p => { if (p?.status?.[0] === 'Published') { if (p?.slug?.indexOf('http') === 0) { customNav.push({ icon: p.icon || null, name: p.title, to: p.slug, show: true }) @@ -239,10 +236,10 @@ async function getPageRecordMapByNotionAPI({ pageId, from }) { const tagOptions = getTagOptions(schema) const categoryOptions = getCategoryOptions(schema) const viewIds = rawMetadata?.view_ids - const data = [] + const collectionData = [] const pageIds = getAllPageIds(collectionQuery, collectionId, collectionView, viewIds) 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++) { const id = pageIds[i] @@ -251,23 +248,34 @@ async function getPageRecordMapByNotionAPI({ pageId, from }) { continue } const properties = (await getPageProperties(id, block, schema, tagOptions)) || null - data.push(properties) + collectionData.push(properties) } - const allPage = data.filter(post => { - return post.title && (post?.status?.[0] === 'Published' || post?.status?.[0] === 'Invisible') && ['Page'].indexOf(post?.type?.[0]) > -1 + const allPages = collectionData.filter(post => { + return post.title && ['Page'].indexOf(post?.type?.[0]) > -1 && (post?.status?.[0] === 'Published' || post?.status?.[0] === 'Invisible') }) - const allPosts = data.filter(post => { - return post.title && post?.status?.[0] === 'Published' && ['Post'].indexOf(post?.type?.[0]) > -1 + const allPosts = collectionData.filter(post => { + 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 categories = getAllCategories({ allPosts, categoryOptions, sliceCount: BLOG.PREVIEW_CATEGORY_COUNT }) const tags = getAllTags({ allPosts, tagOptions, sliceCount: BLOG.PREVIEW_TAG_COUNT }) const latestPosts = getLatestPosts({ allPosts, from, latestPostCount: 5 }) return { + allPages, + allPosts, collection, collectionQuery, collectionId, diff --git a/pages/[slug].js b/pages/[slug].js index 43c98844..16f67e6c 100644 --- a/pages/[slug].js +++ b/pages/[slug].js @@ -80,12 +80,10 @@ export async function getStaticPaths() { } const from = 'slug-paths' - const { allPosts } = await getGlobalNotionData({ from, pageType: ['Page'] }) - const filterPosts = - allPosts?.filter(e => e?.slug?.indexOf('http') !== 0) || [] + const { allPages } = await getGlobalNotionData({ from, pageType: ['Page'] }) return { - paths: filterPosts.map(row => ({ params: { slug: row.slug } })), + paths: allPages.map(row => ({ params: { slug: row.slug } })), fallback: true } } @@ -93,19 +91,19 @@ export async function getStaticPaths() { export async function getStaticProps({ params: { slug } }) { const from = `slug-props-${slug}` const props = await getGlobalNotionData({ from, pageType: ['Page'] }) - const { allPosts } = props - const post = allPosts.find(p => p.slug === slug) - if (!post) { + const { allPages } = props + const page = allPages?.find(p => p.slug === slug) + if (!page) { return { props: {}, revalidate: 1 } } try { - post.blockMap = await getPostBlocks(post.id, 'slug') + page.blockMap = await getPostBlocks(page.id, 'slug') } catch (error) { console.error('获取文章详情失败', error) } - props.post = post + props.post = page return { props, From 578b7dfffda5a1ffcd2066b41b78299139a99208 Mon Sep 17 00:00:00 2001 From: tlyong1992 Date: Wed, 18 May 2022 13:57:13 +0800 Subject: [PATCH 4/6] =?UTF-8?q?Fukasawa=20=E5=BE=AE=E8=B0=83=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- themes/fukasawa/components/ArticleDetail.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/themes/fukasawa/components/ArticleDetail.js b/themes/fukasawa/components/ArticleDetail.js index 2fad01ce..78957330 100644 --- a/themes/fukasawa/components/ArticleDetail.js +++ b/themes/fukasawa/components/ArticleDetail.js @@ -37,13 +37,16 @@ export default function ArticleDetail(props) {
- - - - {post.category} - - - | + + {post?.category && (<> + + + + {post.category} + + + | + )} {post?.type[0] !== 'Page' && (<> Date: Wed, 18 May 2022 14:21:13 +0800 Subject: [PATCH 5/6] =?UTF-8?q?og:image=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/CommonHead.js | 2 +- pages/404.js | 4 ++-- pages/archive/index.js | 1 + pages/article/[slug].js | 5 ++--- pages/category/[category].js | 1 + pages/category/index.js | 1 + pages/page/[page].js | 1 + pages/search/[keyword].js | 1 + pages/search/index.js | 1 + pages/tag/[tag].js | 1 + pages/tag/index.js | 1 + themes/hexo/LayoutBase.js | 2 +- 12 files changed, 14 insertions(+), 7 deletions(-) diff --git a/components/CommonHead.js b/components/CommonHead.js index 7f129995..f4fe840a 100644 --- a/components/CommonHead.js +++ b/components/CommonHead.js @@ -6,7 +6,7 @@ const CommonHead = ({ meta, children }) => { let image if (meta) { url = `${url}/${meta.slug}` - image = meta.image || '' + image = meta.image || '/bg_image.jpg' } const title = meta?.title || BLOG.TITLE const description = meta?.description || BLOG.DESCRIPTION diff --git a/pages/404.js b/pages/404.js index b5a3ca8d..43172bfb 100644 --- a/pages/404.js +++ b/pages/404.js @@ -8,9 +8,9 @@ import { useGlobal } from '@/lib/global' * @returns */ const NoFound = props => { - const { theme } = useGlobal() + const { theme, siteInfo } = useGlobal() const ThemeComponents = ThemeMap[theme] - const meta = { title: `${props?.siteInfo?.title} | 页面找不到啦` } + const meta = { title: `${props?.siteInfo?.title} | 页面找不到啦`, image: siteInfo?.pageCover } return } diff --git a/pages/archive/index.js b/pages/archive/index.js index e66b2abd..fda51dc5 100644 --- a/pages/archive/index.js +++ b/pages/archive/index.js @@ -10,6 +10,7 @@ const ArchiveIndex = props => { const meta = { title: `${locale.NAV.ARCHIVE} | ${siteInfo?.title}`, description: siteInfo?.description, + image: siteInfo?.pageCover, slug: 'archive', type: 'website' } diff --git a/pages/article/[slug].js b/pages/article/[slug].js index 52a2082d..89a42833 100644 --- a/pages/article/[slug].js +++ b/pages/article/[slug].js @@ -15,7 +15,7 @@ import { useRouter } from 'next/router' const Slug = props => { const { theme, changeLoadingState } = useGlobal() const ThemeComponents = ThemeMap[theme] - const { post } = props + const { post, siteInfo } = props if (!post) { changeLoadingState(true) @@ -30,7 +30,7 @@ const Slug = props => { } } }, 10000) - const meta = { title: `${props?.siteInfo?.title || BLOG.TITLE} | loading` } + const meta = { title: `${props?.siteInfo?.title || BLOG.TITLE} | loading`, image: siteInfo?.pageCover } return } @@ -58,7 +58,6 @@ const Slug = props => { props = { ...props, lock, setLock, validPassword } - const { siteInfo } = props const meta = { title: `${post?.title} | ${siteInfo?.title}`, description: post?.summary, diff --git a/pages/category/[category].js b/pages/category/[category].js index 80281a01..ac44bb05 100644 --- a/pages/category/[category].js +++ b/pages/category/[category].js @@ -17,6 +17,7 @@ export default function Category(props) { }`, description: siteInfo?.description, slug: 'category/' + props.category, + image: siteInfo?.pageCover, type: 'website' } return diff --git a/pages/category/index.js b/pages/category/index.js index f099d29f..13f95eee 100644 --- a/pages/category/index.js +++ b/pages/category/index.js @@ -11,6 +11,7 @@ export default function Category(props) { const meta = { title: `${locale.COMMON.CATEGORY} | ${siteInfo?.title}`, description: siteInfo?.description, + image: siteInfo?.pageCover, slug: 'category', type: 'website' } diff --git a/pages/page/[page].js b/pages/page/[page].js index b6787758..f86b0902 100644 --- a/pages/page/[page].js +++ b/pages/page/[page].js @@ -14,6 +14,7 @@ const Page = props => { const meta = { title: `${props.page} | Page | ${siteInfo?.title}`, description: siteInfo?.description, + image: siteInfo?.pageCover, slug: 'page/' + props.page, type: 'website' } diff --git a/pages/search/[keyword].js b/pages/search/[keyword].js index 1607cb90..03fb8109 100644 --- a/pages/search/[keyword].js +++ b/pages/search/[keyword].js @@ -10,6 +10,7 @@ const Index = props => { const meta = { title: `${keyword || ''}${keyword ? ' | ' : ''}${locale.NAV.SEARCH} | ${siteInfo?.title}`, description: siteInfo?.title, + image: siteInfo?.pageCover, slug: 'search/' + (keyword || ''), type: 'website' } diff --git a/pages/search/index.js b/pages/search/index.js index 80cfe52c..30e97c95 100644 --- a/pages/search/index.js +++ b/pages/search/index.js @@ -26,6 +26,7 @@ const Search = props => { siteInfo?.title }`, description: siteInfo?.description, + image: siteInfo?.pageCover, slug: 'search', type: 'website' } diff --git a/pages/tag/[tag].js b/pages/tag/[tag].js index be89d2fa..121dc973 100644 --- a/pages/tag/[tag].js +++ b/pages/tag/[tag].js @@ -15,6 +15,7 @@ const Tag = props => { const meta = { title: `${tag} | ${locale.COMMON.TAGS} | ${siteInfo?.title}`, description: siteInfo?.description, + image: siteInfo?.pageCover, slug: 'tag/' + tag, type: 'website' } diff --git a/pages/tag/index.js b/pages/tag/index.js index 302511dc..1ceb0f07 100644 --- a/pages/tag/index.js +++ b/pages/tag/index.js @@ -11,6 +11,7 @@ const TagIndex = props => { const meta = { title: `${locale.COMMON.TAGS} | ${siteInfo?.title}`, description: siteInfo?.description, + image: siteInfo?.pageCover, slug: 'tag', type: 'website' } diff --git a/themes/hexo/LayoutBase.js b/themes/hexo/LayoutBase.js index c8ca3f8a..ff45d646 100644 --- a/themes/hexo/LayoutBase.js +++ b/themes/hexo/LayoutBase.js @@ -53,7 +53,7 @@ const LayoutBase = props => { return (
- + From 8b0a3e9936e1a0d5efccd52c8bda0d717135d313 Mon Sep 17 00:00:00 2001 From: tlyong1992 Date: Wed, 18 May 2022 14:38:40 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E7=89=88=E6=9C=AC=20V3.3.6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.local | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.env.local b/.env.local index b24ee712..c1efd7f1 100644 --- a/.env.local +++ b/.env.local @@ -1,2 +1,2 @@ # 环境变量 @see https://www.nextjs.cn/docs/basic-features/environment-variables -NEXT_PUBLIC_VERSION=3.3.5 \ No newline at end of file +NEXT_PUBLIC_VERSION=3.3.6 \ No newline at end of file diff --git a/package.json b/package.json index 0cc4a8a2..f6b327a4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "notion-next", - "version": "3.3.5", + "version": "3.3.6", "homepage": "https://github.com/tangly1024/NotionNext.git", "license": "MIT", "repository": {