Merge pull request #1220 from tangly1024/fix/article-publish-date

调整文章日期显示
This commit is contained in:
tangly1024
2023-06-29 12:45:08 +08:00
committed by GitHub
31 changed files with 61 additions and 67 deletions

View File

@@ -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
})
}

View File

@@ -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
})
}

View File

@@ -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)

View File

@@ -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)
})
}

View File

@@ -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'
})
})

View File

@@ -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
})

View File

@@ -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'
}

View File

@@ -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"
>
<div id={post?.date?.start_date}>
<div id={post?.publishTime}>
<span className="text-gray-400">
{post.date?.start_date}
</span>{' '}

View File

@@ -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 (
<section className="flex-wrap flex mt-2 text-gray-400 dark:text-gray-400 font-light leading-8">
@@ -26,11 +24,11 @@ export const ArticleInfo = (props) => {
{post?.type !== 'Page' && (<>
<Link
href={`/archive#${post?.date?.start_date?.substr(0, 7)}`}
href={`/archive#${post?.publishTime?.substr(0, 7)}`}
passHref
className="pl-1 mr-2 cursor-pointer hover:text-gray-700 dark:hover:text-gray-200 border-b dark:border-gray-500 border-dashed">
{date}
{post?.publishTime}
</Link>
<span className='mr-2'>|</span>

View File

@@ -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 (
<div id="container" className="max-w-5xl overflow-x-auto flex-grow mx-auto w-screen md:w-full ">
{post?.type && !post?.type !== 'Page' && post?.pageCover && (
@@ -57,7 +57,7 @@ export default function ArticleDetail(props) {
{post?.type !== 'Page' && (<>
<Link
href={`/archive#${post?.date?.start_date?.substr(0, 7)}`}
href={`/archive#${post?.publishTime?.substr(0, 7)}`}
passHref
className="pl-1 mr-2 cursor-pointer hover:text-gray-700 dark:hover:text-gray-200 border-b dark:border-gray-500 border-dashed">

View File

@@ -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"
>
<div id={post?.date?.start_date}>
<div id={post?.publishTime}>
<span className="text-gray-400">{post.date?.start_date}</span>{' '}
&nbsp;
<Link

View File

@@ -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"
>
<div id={post?.date?.start_date}>
<div id={post?.publishTime}>
<span className="text-gray-400">
{post.date?.start_date}
</span>{' '}

View File

@@ -21,7 +21,7 @@ export const LayoutIndex = (props) => {
console.log('请检查您的Notion数据库中是否包含此slug页面 ', CONFIG_GITBOOK.INDEX_PAGE)
const containerInner = document.getElementById('container-inner')
const newHTML = `<h1 class="text-3xl pt-12 dark:text-gray-300">配置有误</h1><blockquote class="notion-quote notion-block-ce76391f3f2842d386468ff1eb705b92"><div>请在您的notion中添加一个slug为${CONFIG_GITBOOK.INDEX_PAGE}的文章</div></blockquote>`
containerInner.insertAdjacentHTML('afterbegin', newHTML)
containerInner?.insertAdjacentHTML('afterbegin', newHTML)
}
}
}, 7 * 1000)

View File

@@ -8,7 +8,7 @@ import React from 'react'
export const LayoutIndex = (props) => {
const headerSlot = CONFIG_HEXO.HOME_BANNER_ENABLE && <Header {...props} />
return <LayoutBase {...props} headerSlot={headerSlot}>
return <LayoutBase {...props} headerSlot={headerSlot} className='pt-8'>
{BLOG.POST_LIST_STYLE === 'page' ? <BlogPostListPage {...props} /> : <BlogPostListScroll {...props} />}
</LayoutBase>
}

View File

@@ -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"
>
<div id={post?.date?.start_date}>
<div id={post?.publishTime}>
<span className="text-gray-400">{post.date?.start_date}</span>{' '}
&nbsp;
<Link

View File

@@ -24,7 +24,7 @@ export const BlogPostCardInfo = ({ post, showPreview, showPageCover, showSummary
</Link>
{/* 分类 */}
<div
{ post?.category && <div
className={`flex mt-2 items-center ${showPreview ? 'justify-center' : 'justify-start'
} flex-wrap dark:text-gray-500 text-gray-400 `}
>
@@ -39,7 +39,7 @@ export const BlogPostCardInfo = ({ post, showPreview, showPageCover, showSummary
</Link>
<TwikooCommentCount className='text-sm hover:text-indigo-700 dark:hover:text-indigo-400' post={post}/>
</div>
</div>}
{/* 摘要 */}
{(!showPreview || showSummary) && !post.results && (
@@ -70,12 +70,12 @@ export const BlogPostCardInfo = ({ post, showPreview, showPageCover, showSummary
<div className="text-gray-400 justify-between flex">
{/* 日期 */}
<Link
href={`/archive#${post?.date?.start_date?.substr(0, 7)}`}
href={`/archive#${post?.publishTime?.substr(0, 7)}`}
passHref
className="font-light menu-link cursor-pointer text-sm leading-4 mr-3">
<i className="far fa-calendar-alt mr-1" />
{post.date?.start_date || post.lastEditedTime}
{post?.publishTime || post.lastEditedTime}
</Link>

View File

@@ -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' && (
<>
<Link
href={`/archive#${post?.date?.start_date?.substr(0, 7)}`}
href={`/archive#${post?.publishTime?.substr(0, 7)}`}
passHref
className="pl-1 mr-2 cursor-pointer hover:underline">

View File

@@ -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 (
<section className='mb-3 dark:text-gray-200'>
@@ -25,7 +25,7 @@ export const ArticleInfo = (props) => {
<div className='flex flex-wrap gap-3 mt-5 text-sm'>
{post?.type !== 'Page' && (<>
<Link
href={`/archive#${post?.date?.start_date?.substr(0, 7)}`}
href={`/archive#${post?.publishTime?.substr(0, 7)}`}
passHref
className="cursor-pointer whitespace-nowrap">

View File

@@ -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"
>
<div id={post?.date?.start_date}>
<div id={post?.publishTime}>
<span className="text-gray-400">{post.date?.start_date}</span>{' '}
&nbsp;
<Link

View File

@@ -57,7 +57,7 @@ const BlogPostCard = ({ index, post, showSummary, siteInfo }) => {
<div className='text-gray-800 justify-between flex my-2 dark:text-gray-300'>
<div>
<Link
href={`/archive#${post?.date?.start_date?.substr(0, 7)}`}
href={`/archive#${post?.publishTime?.substr(0, 7)}`}
passHref
className="font-light hover:underline cursor-pointer text-sm leading-4 mr-3">

View File

@@ -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"
>
<div id={post?.date?.start_date}>
<div id={post?.publishTime}>
<span className="text-gray-400">
{post.date?.start_date}
</span>{' '}

View File

@@ -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) {

View File

@@ -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 (
<div id="container"
@@ -56,11 +54,11 @@ export default function ArticleDetail(props) {
<div className='flex flex-wrap justify-center'>
{post?.type !== 'Page' && (<>
<Link
href={`/archive#${post?.date?.start_date?.substr(0, 7)}`}
href={`/archive#${post?.publishTime?.substr(0, 7)}`}
passHref
legacyBehavior>
<div className="pl-1 mr-2 cursor-pointer hover:text-gray-700 dark:hover:text-gray-200 border-b dark:border-gray-500 border-dashed">
<i className='far fa-calendar mr-1' /> {date}
<i className='far fa-calendar mr-1' /> {post?.publishTime}
</div>
</Link>
<span className='mr-2'> | <i className='far fa-calendar-check mr-2' />{post.lastEditedTime} </span>

View File

@@ -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"
>
<div id={post?.date?.start_date}>
<div id={post?.publishTime}>
<span className="text-gray-400">{post.date?.start_date}</span>{' '}
&nbsp;
<Link

View File

@@ -57,7 +57,7 @@ const BlogPostCard = ({ post, showSummary }) => {
</>
)}
<Link
href={`/archive#${post?.date?.start_date?.substr(0, 7)}`}
href={`/archive#${post?.publishTime?.substr(0, 7)}`}
passHref
className="hover:text-blue-500 dark:hover:text-blue-400 font-light hover:underline cursor-pointer text-sm leading-4 mr-3">
{post.date?.start_date}

View File

@@ -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"
>
<div id={post?.date?.start_date}>
<div id={post?.publishTime}>
<span className="text-gray-400">
{post.date?.start_date}
</span>{' '}

View File

@@ -34,7 +34,7 @@ export const ArticleInfo = (props) => {
</div>
<div className="mr-2 mb-4 md:ml-0">
{formatDate(
post?.date?.start_date || post.createdTime,
post?.publishTime || post.createdTime,
BLOG.LANG
)}
</div>

View File

@@ -12,7 +12,7 @@ const BlogPost = ({ post }) => {
{post.title}
</h2>
<time className="flex-shrink-0 text-gray-600 dark:text-gray-400">
{formatDate(post?.date?.start_date || post.createdTime, BLOG.LANG)}
{formatDate(post?.publishTime || post.createdTime, BLOG.LANG)}
</time>
</header>
<main>

View File

@@ -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"
>
<div id={post?.date?.start_date}>
<div id={post?.publishTime}>
<span className="text-gray-400">
{post.date?.start_date}
</span>{' '}

View File

@@ -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 (
<section className="flex-wrap flex mt-2 text-gray-400 dark:text-gray-400 font-light leading-8">
@@ -21,21 +19,21 @@ export const ArticleInfo = (props) => {
{post?.type !== 'Page' && (<>
<div className="mb-4 text-sm text-gray-700 dark:text-gray-300">
<span> <i className="fa-regular fa-user"></i> <a href={CONFIG_SIMPLE.AUTHOR_LINK}>{BLOG.AUTHOR}</a></span>
<span> - <i className="fa-regular fa-clock"></i> {post?.date?.start_date || post?.createdTime}</span>
<span> - <i className="fa-regular fa-clock"></i> {post?.publishTime}</span>
{post?.category && <span> - <i className="fa-regular fa-folder"></i> <a href={`/category/${post?.category}`} className="hover:text-red-400 transition-all duration-200">{post?.category}</a></span>}
{post?.tags && post.tags?.length > 0 && post?.tags.map(t => <span key={t}> / <Link href={`/tag/${t}`}><span className=' hover:text-red-400 transition-all duration-200'>{t}</span></Link></span>)}
</div>
</>)}
{post?.type !== 'Page' && (<>
<Link
href={`/archive#${post?.date?.start_date?.substr(0, 7)}`}
passHref
className="pl-1 mr-2 cursor-pointer hover:text-gray-700 dark:hover:text-gray-200 border-b dark:border-gray-500 border-dashed">
{date}
</Link>
<span>{locale.COMMON.POST_TIME}:
<Link
href={`/archive#${post?.publishTime?.substr(0, 7)}`}
passHref
className="pl-1 mr-2 cursor-pointer hover:text-gray-700 dark:hover:text-gray-200 border-b dark:border-gray-500 border-dashed">
{post?.publishTime}
</Link>
</span>
<span className='mr-2'>|</span>
<span className='mx-2 text-gray-400 dark:text-gray-500'>
{locale.COMMON.LAST_EDITED_TIME}: {post?.lastEditedTime}

View File

@@ -23,7 +23,7 @@ export const BlogItem = props => {
<div className='space-x-2'>
<span> <a href={CONFIG_SIMPLE.AUTHOR_LINK} className='p-1 hover:text-red-400 transition-all duration-200'><i className="fa-regular fa-user"></i> {BLOG.AUTHOR}</a></span>
<span>
<Link className='p-1 hover:text-red-400 transition-all duration-200' href={`/archive#${post?.date?.start_date?.substr(0, 7)}`}>
<Link className='p-1 hover:text-red-400 transition-all duration-200' href={`/archive#${post?.publishTime?.substr(0, 7)}`}>
<i className="fa-regular fa-clock" /> {post.date?.start_date || post.createdTime}
</Link>
</span>