From 9ac2bbb1804d5d88ff28e3cee44fe7db4d1eea54 Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Thu, 29 Jun 2023 12:44:46 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=96=87=E7=AB=A0=E6=97=A5?= =?UTF-8?q?=E6=9C=9F=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/notion/getAllPosts.js | 4 ++-- lib/notion/getNotionData.js | 8 +++----- lib/notion/getPageProperties.js | 20 ++++++++++--------- lib/rss.js | 2 +- lib/sitemap.xml.js | 2 +- pages/archive/index.js | 4 ++-- pages/sitemap.xml.js | 2 +- themes/example/LayoutArchive.js | 2 +- themes/example/components/ArticleInfo.js | 6 ++---- themes/fukasawa/components/ArticleDetail.js | 4 ++-- themes/fukasawa/components/BlogPostArchive.js | 2 +- themes/gitbook/LayoutArchive.js | 2 +- themes/gitbook/LayoutIndex.js | 2 +- themes/hexo/LayoutIndex.js | 2 +- themes/hexo/components/BlogPostArchive.js | 2 +- themes/hexo/components/BlogPostCardInfo.js | 8 ++++---- themes/hexo/components/HeaderArticle.js | 4 ++-- themes/matery/components/ArticleInfo.js | 4 ++-- themes/matery/components/BlogPostArchive.js | 2 +- themes/matery/components/BlogPostCard.js | 2 +- themes/medium/LayoutArchive.js | 2 +- themes/medium/LayoutSlug.js | 2 +- themes/next/components/ArticleDetail.js | 6 ++---- themes/next/components/BlogPostArchive.js | 2 +- themes/next/components/BlogPostCard.js | 2 +- themes/nobelium/LayoutArchive.js | 2 +- themes/nobelium/components/ArticleInfo.js | 2 +- themes/nobelium/components/BlogPost.js | 2 +- themes/simple/LayoutArchive.js | 2 +- themes/simple/components/ArticleInfo.js | 20 +++++++++---------- themes/simple/components/BlogItem.js | 2 +- 31 files changed, 61 insertions(+), 67 deletions(-) diff --git a/lib/notion/getAllPosts.js b/lib/notion/getAllPosts.js index bfd1878d..3f9d2579 100644 --- a/lib/notion/getAllPosts.js +++ b/lib/notion/getAllPosts.js @@ -45,8 +45,8 @@ export async function getAllPosts({ notionPageData, from, pageType }) { // 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) + const dateA = new Date(a?.publishTime || a.createdTime) + const dateB = new Date(b?.publishTime || b.createdTime) return dateB - dateA }) } diff --git a/lib/notion/getNotionData.js b/lib/notion/getNotionData.js index 688e2c0a..43fb139a 100644 --- a/lib/notion/getNotionData.js +++ b/lib/notion/getNotionData.js @@ -48,8 +48,8 @@ function getLatestPosts({ allPages, from, latestPostCount }) { const allPosts = allPages?.filter(page => page.type === 'Post' && page.status === 'Published') const latestPosts = Object.create(allPosts).sort((a, b) => { - const dateA = new Date(a?.lastEditedTime || a?.createdTime || a?.date?.start_date) - const dateB = new Date(b?.lastEditedTime || b?.createdTime || b?.date?.start_date) + const dateA = new Date(a?.lastEditedTime || a?.createdTime || a?.publishTime) + const dateB = new Date(b?.lastEditedTime || b?.createdTime || b?.publishTime) return dateB - dateA }) return latestPosts.slice(0, latestPostCount) @@ -298,9 +298,7 @@ async function getDataBaseInfoByNotionAPI({ pageId, from }) { // Sort by date if (BLOG.POSTS_SORT_BY === 'date') { allPages.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 b.publishTime - a.publishTime }) } diff --git a/lib/notion/getPageProperties.js b/lib/notion/getPageProperties.js index 0a420727..a08a7572 100644 --- a/lib/notion/getPageProperties.js +++ b/lib/notion/getPageProperties.js @@ -94,15 +94,14 @@ export default async function getPageProperties(id, block, schema, authToken, ta } properties.createdTime = formatDate(new Date(value.created_time).toString(), BLOG.LANG) + properties.publishTime = value?.date?.start_date ? formatDate(new Date(value?.date?.start_date).toString, BLOG.LANG) : properties.createdTime properties.lastEditedTime = formatDate(new Date(value?.last_edited_time).toString(), BLOG.LANG) properties.fullWidth = value.format?.page_full_width ?? false properties.pageIcon = mapImgUrl(block[id].value?.format?.page_icon, block[id].value) ?? '' properties.pageCover = mapImgUrl(block[id].value?.format?.page_cover, block[id].value) ?? '' properties.pageCoverThumbnail = mapImgUrl(block[id].value?.format?.page_cover, block[id].value, 'block', 'pageCoverThumbnail') ?? '' properties.content = value.content ?? [] - properties.password = properties.password - ? md5(properties.slug + properties.password) - : '' + properties.password = properties.password ? md5(properties.slug + properties.password) : '' properties.tagItems = properties?.tags?.map(tag => { return { name: tag, color: tagOptions?.find(t => t.value === tag)?.color || 'gray' } }) || [] @@ -110,6 +109,9 @@ export default async function getPageProperties(id, block, schema, authToken, ta return properties } +/** + * 映射用户自定义表头 + */ function mapProperties(properties) { if (properties?.type === BLOG.NOTION_PROPERTY_NAME.type_post) { properties.type = 'Post' @@ -132,14 +134,14 @@ function generateCustomizeUrl(postProperties) { let fullSlug = '' const allSlugPatterns = BLOG.POST_URL_PREFIX.split('/') allSlugPatterns.forEach((pattern, idx) => { - if (pattern === '%year%' && postProperties?.date?.start_date) { - const formatPostCreatedDate = new Date(postProperties?.date?.start_date) + if (pattern === '%year%' && postProperties?.publishTime) { + const formatPostCreatedDate = new Date(postProperties?.publishTime) fullSlug += formatPostCreatedDate.getUTCFullYear() - } else if (pattern === '%month%' && postProperties?.date?.start_date) { - const formatPostCreatedDate = new Date(postProperties?.date?.start_date) + } else if (pattern === '%month%' && postProperties?.publishTime) { + const formatPostCreatedDate = new Date(postProperties?.publishTime) fullSlug += String(formatPostCreatedDate.getUTCMonth() + 1).padStart(2, 0) - } else if (pattern === '%day%' && postProperties?.date?.start_date) { - const formatPostCreatedDate = new Date(postProperties?.date?.start_date) + } else if (pattern === '%day%' && postProperties?.publishTime) { + const formatPostCreatedDate = new Date(postProperties?.publishTime) fullSlug += String(formatPostCreatedDate.getUTCDate()).padStart(2, 0) } else if (pattern === '%slug%') { fullSlug += (postProperties.slug ?? postProperties.id) diff --git a/lib/rss.js b/lib/rss.js index 02121d49..88f213e7 100644 --- a/lib/rss.js +++ b/lib/rss.js @@ -46,7 +46,7 @@ export async function generateRss(posts) { link: `${BLOG.LINK}/${post.slug}`, description: post.summary, content: await createFeedContent(post), - date: new Date(post?.date?.start_date || post?.createdTime) + date: new Date(post?.publishTime || post?.createdTime) }) } diff --git a/lib/sitemap.xml.js b/lib/sitemap.xml.js index 7522951d..5a626e75 100644 --- a/lib/sitemap.xml.js +++ b/lib/sitemap.xml.js @@ -24,7 +24,7 @@ export async function generateSitemapXml({ allPages }) { allPages?.forEach(post => { urls.push({ loc: `${BLOG.LINK}/${post.slug}`, - lastmod: new Date(post?.date?.start_date || post?.createdTime).toISOString().split('T')[0], + lastmod: new Date(post?.publishTime || post?.createdTime).toISOString().split('T')[0], changefreq: 'daily' }) }) diff --git a/pages/archive/index.js b/pages/archive/index.js index 567fa83b..6d0ebe32 100644 --- a/pages/archive/index.js +++ b/pages/archive/index.js @@ -34,8 +34,8 @@ export async function getStaticProps() { const postsSortByDate = Object.create(props.posts) postsSortByDate.sort((a, b) => { - const dateA = new Date(a?.date?.start_date || a.createdTime) - const dateB = new Date(b?.date?.start_date || b.createdTime) + const dateA = new Date(a?.publishTime || a.createdTime) + const dateB = new Date(b?.publishTime || b.createdTime) return dateB - dateA }) diff --git a/pages/sitemap.xml.js b/pages/sitemap.xml.js index 8f753f5d..9dbb5ab7 100644 --- a/pages/sitemap.xml.js +++ b/pages/sitemap.xml.js @@ -41,7 +41,7 @@ export const getServerSideProps = async (ctx) => { const postFields = allPages?.filter(p => p.status === BLOG.NOTION_PROPERTY_NAME.status_publish)?.map(post => { return { loc: `${BLOG.LINK}/${post.slug}`, - lastmod: new Date(post?.date?.start_date || post?.createdTime).toISOString().split('T')[0], + lastmod: new Date(post?.publishTime || post?.createdTime).toISOString().split('T')[0], changefreq: 'daily', priority: '0.7' } diff --git a/themes/example/LayoutArchive.js b/themes/example/LayoutArchive.js index 81ec0781..e36a3210 100644 --- a/themes/example/LayoutArchive.js +++ b/themes/example/LayoutArchive.js @@ -20,7 +20,7 @@ export const LayoutArchive = props => { key={post.id} className="border-l-2 p-1 text-xs md:text-base items-center hover:scale-x-105 hover:border-gray-500 dark:hover:border-gray-300 dark:border-gray-400 transform duration-500" > -
+
{post.date?.start_date} {' '} diff --git a/themes/example/components/ArticleInfo.js b/themes/example/components/ArticleInfo.js index 0b34fb12..9959d219 100644 --- a/themes/example/components/ArticleInfo.js +++ b/themes/example/components/ArticleInfo.js @@ -1,12 +1,10 @@ import Link from 'next/link' import { useGlobal } from '@/lib/global' -import formatDate from '@/lib/formatDate' export const ArticleInfo = (props) => { const { post } = props const { locale } = useGlobal() - const date = formatDate(post?.date?.start_date || post?.createdTime, locale.LOCALE) return (
@@ -26,11 +24,11 @@ export const ArticleInfo = (props) => { {post?.type !== 'Page' && (<> - {date} + {post?.publishTime} | diff --git a/themes/fukasawa/components/ArticleDetail.js b/themes/fukasawa/components/ArticleDetail.js index b9a339d3..8cfdaba4 100644 --- a/themes/fukasawa/components/ArticleDetail.js +++ b/themes/fukasawa/components/ArticleDetail.js @@ -19,7 +19,7 @@ export default function ArticleDetail(props) { if (!post) { return <> } - const date = formatDate(post?.date?.start_date || post?.createdTime, locale.LOCALE) + const date = formatDate(post?.publishTime || post?.createdTime, locale.LOCALE) return (
{post?.type && !post?.type !== 'Page' && post?.pageCover && ( @@ -57,7 +57,7 @@ export default function ArticleDetail(props) { {post?.type !== 'Page' && (<> diff --git a/themes/fukasawa/components/BlogPostArchive.js b/themes/fukasawa/components/BlogPostArchive.js index a86210db..ba68f8cf 100644 --- a/themes/fukasawa/components/BlogPostArchive.js +++ b/themes/fukasawa/components/BlogPostArchive.js @@ -26,7 +26,7 @@ const BlogArchiveItem = ({ posts = [], archiveTitle }) => { key={post.id} className="border-l-2 p-1 text-xs md:text-base items-center hover:scale-x-105 hover:border-gray-500 dark:hover:border-gray-300 dark:border-gray-400 transform duration-500" > -
+
{post.date?.start_date}{' '}   { key={post.id} className="border-l-2 p-1 text-xs md:text-base items-center hover:scale-x-105 hover:border-gray-500 dark:hover:border-gray-300 dark:border-gray-400 transform duration-500" > -
+
{post.date?.start_date} {' '} diff --git a/themes/gitbook/LayoutIndex.js b/themes/gitbook/LayoutIndex.js index e259a80a..0b4bd7b0 100644 --- a/themes/gitbook/LayoutIndex.js +++ b/themes/gitbook/LayoutIndex.js @@ -21,7 +21,7 @@ export const LayoutIndex = (props) => { console.log('请检查您的Notion数据库中是否包含此slug页面: ', CONFIG_GITBOOK.INDEX_PAGE) const containerInner = document.getElementById('container-inner') const newHTML = `

配置有误

请在您的notion中添加一个slug为${CONFIG_GITBOOK.INDEX_PAGE}的文章
` - containerInner.insertAdjacentHTML('afterbegin', newHTML) + containerInner?.insertAdjacentHTML('afterbegin', newHTML) } } }, 7 * 1000) diff --git a/themes/hexo/LayoutIndex.js b/themes/hexo/LayoutIndex.js index 388e69bf..2d7a1a95 100644 --- a/themes/hexo/LayoutIndex.js +++ b/themes/hexo/LayoutIndex.js @@ -8,7 +8,7 @@ import React from 'react' export const LayoutIndex = (props) => { const headerSlot = CONFIG_HEXO.HOME_BANNER_ENABLE &&
- return + return {BLOG.POST_LIST_STYLE === 'page' ? : } } diff --git a/themes/hexo/components/BlogPostArchive.js b/themes/hexo/components/BlogPostArchive.js index f90f4c03..08feff4c 100644 --- a/themes/hexo/components/BlogPostArchive.js +++ b/themes/hexo/components/BlogPostArchive.js @@ -26,7 +26,7 @@ const BlogPostArchive = ({ posts = [], archiveTitle }) => { key={post.id} className="border-l-2 p-1 text-xs md:text-base items-center hover:scale-x-105 hover:border-indigo-500 dark:hover:border-indigo-300 dark:border-indigo-400 transform duration-500" > -
+
{post.date?.start_date}{' '}   {/* 分类 */} -
@@ -39,7 +39,7 @@ export const BlogPostCardInfo = ({ post, showPreview, showPageCover, showSummary -
+
} {/* 摘要 */} {(!showPreview || showSummary) && !post.results && ( @@ -70,12 +70,12 @@ export const BlogPostCardInfo = ({ post, showPreview, showPageCover, showSummary
{/* 日期 */} - {post.date?.start_date || post.lastEditedTime} + {post?.publishTime || post.lastEditedTime} diff --git a/themes/hexo/components/HeaderArticle.js b/themes/hexo/components/HeaderArticle.js index 9d47074b..c6867b9a 100644 --- a/themes/hexo/components/HeaderArticle.js +++ b/themes/hexo/components/HeaderArticle.js @@ -14,7 +14,7 @@ export default function HeaderArticle({ post, siteInfo }) { const headerImage = post?.pageCover ? `url("${post.pageCover}")` : `url("${siteInfo?.pageCover}")` const date = formatDate( - post?.date?.start_date || post?.createdTime, + post?.publishTime || post?.createdTime, locale.LOCALE ) @@ -57,7 +57,7 @@ export default function HeaderArticle({ post, siteInfo }) { {post?.type !== 'Page' && ( <> diff --git a/themes/matery/components/ArticleInfo.js b/themes/matery/components/ArticleInfo.js index 09c6e3ec..c806028d 100644 --- a/themes/matery/components/ArticleInfo.js +++ b/themes/matery/components/ArticleInfo.js @@ -8,7 +8,7 @@ export const ArticleInfo = (props) => { const { post } = props const { locale } = useGlobal() - const date = formatDate(post?.date?.start_date || post?.createdTime, locale.LOCALE) + const date = formatDate(post?.publishTime || post?.createdTime, locale.LOCALE) return (
@@ -25,7 +25,7 @@ export const ArticleInfo = (props) => {
{post?.type !== 'Page' && (<> diff --git a/themes/matery/components/BlogPostArchive.js b/themes/matery/components/BlogPostArchive.js index f90f4c03..08feff4c 100644 --- a/themes/matery/components/BlogPostArchive.js +++ b/themes/matery/components/BlogPostArchive.js @@ -26,7 +26,7 @@ const BlogPostArchive = ({ posts = [], archiveTitle }) => { key={post.id} className="border-l-2 p-1 text-xs md:text-base items-center hover:scale-x-105 hover:border-indigo-500 dark:hover:border-indigo-300 dark:border-indigo-400 transform duration-500" > -
+
{post.date?.start_date}{' '}   {
diff --git a/themes/medium/LayoutArchive.js b/themes/medium/LayoutArchive.js index 101b7119..083dd8ac 100644 --- a/themes/medium/LayoutArchive.js +++ b/themes/medium/LayoutArchive.js @@ -22,7 +22,7 @@ export const LayoutArchive = props => { key={post.id} className="border-l-2 p-1 text-xs md:text-base items-center hover:scale-x-105 hover:border-gray-500 dark:hover:border-gray-300 dark:border-gray-400 transform duration-500" > -
+
{post.date?.start_date} {' '} diff --git a/themes/medium/LayoutSlug.js b/themes/medium/LayoutSlug.js index 1d235f32..39b4103e 100644 --- a/themes/medium/LayoutSlug.js +++ b/themes/medium/LayoutSlug.js @@ -20,7 +20,7 @@ export const LayoutSlug = props => { const { locale } = useGlobal() const date = formatDate( - post?.date?.start_date || post?.createdTime, + post?.publishTime || post?.createdTime, locale.LOCALE ) if (!post) { diff --git a/themes/next/components/ArticleDetail.js b/themes/next/components/ArticleDetail.js index 09da7426..9ad41107 100644 --- a/themes/next/components/ArticleDetail.js +++ b/themes/next/components/ArticleDetail.js @@ -4,7 +4,6 @@ import Comment from '@/components/Comment' import RecommendPosts from './RecommendPosts' import ShareBar from '@/components/ShareBar' import TagItem from './TagItem' -import formatDate from '@/lib/formatDate' import { useGlobal } from '@/lib/global' import Link from 'next/link' import { useRouter } from 'next/router' @@ -24,7 +23,6 @@ export default function ArticleDetail(props) { const url = BLOG.LINK + useRouter().asPath const { locale } = useGlobal() const showArticleInfo = CONFIG_NEXT.ARTICLE_INFO - const date = formatDate(post?.date?.start_date || post?.createdTime, locale.LOCALE) return (
{post?.type !== 'Page' && (<>
- {date} + {post?.publishTime}
| {post.lastEditedTime} diff --git a/themes/next/components/BlogPostArchive.js b/themes/next/components/BlogPostArchive.js index a5a1ac6f..a6c0e796 100644 --- a/themes/next/components/BlogPostArchive.js +++ b/themes/next/components/BlogPostArchive.js @@ -26,7 +26,7 @@ const BlogPostArchive = ({ posts = [], archiveTitle }) => { key={post.id} className="border-l-2 p-1 text-xs md:text-base items-center hover:scale-x-105 hover:border-gray-500 dark:hover:border-gray-300 dark:border-gray-400 transform duration-500" > -
+
{post.date?.start_date}{' '}   { )} {post.date?.start_date} diff --git a/themes/nobelium/LayoutArchive.js b/themes/nobelium/LayoutArchive.js index 81ec0781..e36a3210 100644 --- a/themes/nobelium/LayoutArchive.js +++ b/themes/nobelium/LayoutArchive.js @@ -20,7 +20,7 @@ export const LayoutArchive = props => { key={post.id} className="border-l-2 p-1 text-xs md:text-base items-center hover:scale-x-105 hover:border-gray-500 dark:hover:border-gray-300 dark:border-gray-400 transform duration-500" > -
+
{post.date?.start_date} {' '} diff --git a/themes/nobelium/components/ArticleInfo.js b/themes/nobelium/components/ArticleInfo.js index 6b47c884..6e37cad5 100644 --- a/themes/nobelium/components/ArticleInfo.js +++ b/themes/nobelium/components/ArticleInfo.js @@ -34,7 +34,7 @@ export const ArticleInfo = (props) => {
{formatDate( - post?.date?.start_date || post.createdTime, + post?.publishTime || post.createdTime, BLOG.LANG )}
diff --git a/themes/nobelium/components/BlogPost.js b/themes/nobelium/components/BlogPost.js index 9cd717b5..48652cf6 100644 --- a/themes/nobelium/components/BlogPost.js +++ b/themes/nobelium/components/BlogPost.js @@ -12,7 +12,7 @@ const BlogPost = ({ post }) => { {post.title}
diff --git a/themes/simple/LayoutArchive.js b/themes/simple/LayoutArchive.js index 81ec0781..e36a3210 100644 --- a/themes/simple/LayoutArchive.js +++ b/themes/simple/LayoutArchive.js @@ -20,7 +20,7 @@ export const LayoutArchive = props => { key={post.id} className="border-l-2 p-1 text-xs md:text-base items-center hover:scale-x-105 hover:border-gray-500 dark:hover:border-gray-300 dark:border-gray-400 transform duration-500" > -
+
{post.date?.start_date} {' '} diff --git a/themes/simple/components/ArticleInfo.js b/themes/simple/components/ArticleInfo.js index caec6e4c..614d457a 100644 --- a/themes/simple/components/ArticleInfo.js +++ b/themes/simple/components/ArticleInfo.js @@ -1,6 +1,5 @@ import Link from 'next/link' import { useGlobal } from '@/lib/global' -import formatDate from '@/lib/formatDate' import CONFIG_SIMPLE from '../config_simple' import BLOG from '@/blog.config' @@ -8,7 +7,6 @@ export const ArticleInfo = (props) => { const { post } = props const { locale } = useGlobal() - const date = formatDate(post?.date?.start_date || post?.createdTime, locale.LOCALE) return (
@@ -21,21 +19,21 @@ export const ArticleInfo = (props) => { {post?.type !== 'Page' && (<>
{BLOG.AUTHOR} - - {post?.date?.start_date || post?.createdTime} + - {post?.publishTime} {post?.category && - {post?.category}} {post?.tags && post.tags?.length > 0 && post?.tags.map(t => / {t})}
)} {post?.type !== 'Page' && (<> - - - {date} - - + {locale.COMMON.POST_TIME}: + + {post?.publishTime} + + | {locale.COMMON.LAST_EDITED_TIME}: {post?.lastEditedTime} diff --git a/themes/simple/components/BlogItem.js b/themes/simple/components/BlogItem.js index b8896311..c0bd9ecf 100644 --- a/themes/simple/components/BlogItem.js +++ b/themes/simple/components/BlogItem.js @@ -23,7 +23,7 @@ export const BlogItem = props => {
{BLOG.AUTHOR} - + {post.date?.start_date || post.createdTime}