Skip to content

Commit

Permalink
Merge pull request tangly1024#1355 from tangly1024/heo/post-last-edit…
Browse files Browse the repository at this point in the history
…e-time

heo 添加最后更新日期,修复归档日期bug
  • Loading branch information
tangly1024 committed Jul 27, 2023
2 parents a434453 + 2a83af3 commit dffd709
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 12 deletions.
1 change: 1 addition & 0 deletions lib/formatDate.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default function formatDate (date, local) {
const d = new Date(date)
const options = { year: 'numeric', month: 'short', day: 'numeric' }
const res = d.toLocaleDateString(local, options)
// 如果格式是中文日期,则转为横杆
const format = local.slice(0, 2).toLowerCase() === 'zh'
? res.replace('年', '-').replace('月', '-').replace('日', '')
: res
Expand Down
3 changes: 2 additions & 1 deletion themes/example/components/ArticleInfo.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Link from 'next/link'
import { useGlobal } from '@/lib/global'
import { formatDateFmt } from '@/lib/formatDate'

export const ArticleInfo = (props) => {
const { post } = props
Expand All @@ -24,7 +25,7 @@ export const ArticleInfo = (props) => {

{post?.type !== 'Page' && (<>
<Link
href={`/archive#${post?.publishTime?.substr(0, 7)}`}
href={`/archive#${formatDateFmt(post?.publishDate, 'yyyy-MM')}`}
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">

Expand Down
3 changes: 2 additions & 1 deletion themes/fukasawa/components/ArticleDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Link from 'next/link'
import ArticleAround from './ArticleAround'
import { AdSlot } from '@/components/GoogleAdsense'
import LazyImage from '@/components/LazyImage'
import { formatDateFmt } from '@/lib/formatDate'

/**
*
Expand Down Expand Up @@ -54,7 +55,7 @@ export default function ArticleDetail(props) {

{post?.type !== 'Page' && (<>
<Link
href={`/archive#${post?.publishTime?.substr(0, 7)}`}
href={`/archive#${formatDateFmt(post?.publishDate, 'yyyy-MM')}`}
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">

Expand Down
9 changes: 7 additions & 2 deletions themes/heo/components/PostHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import WavesArea from './WavesArea'
import { HashTag } from '@/components/HeroIcons'
import WordCount from '@/components/WordCount'
import LazyImage from '@/components/LazyImage'
import { formatDateFmt } from '@/lib/formatDate'

export default function PostHeader({ post, siteInfo }) {
if (!post) {
Expand Down Expand Up @@ -75,14 +76,18 @@ export default function PostHeader({ post, siteInfo }) {
{post?.type !== 'Page' && (
<>
<Link
href={`/archive#${post?.publishTime?.substr(0, 7)}`}
href={`/archive#${formatDateFmt(post?.publishDate, 'yyyy-MM')}`}
passHref
className="pl-1 mr-2 cursor-pointer hover:underline">
<i className="fa-solid fa-calendar-days"></i> {post?.publishTime}
<i className="fa-regular fa-calendar"></i> {post?.publishTime}
</Link>
</>
)}

<div className="pl-1 mr-2">
<i className="fa-regular fa-calendar-check"></i> {post.lastEditedTime}
</div>

</div>

{JSON.parse(BLOG.ANALYTICS_BUSUANZI_ENABLE) && <div className="busuanzi_container_page_pv font-light mr-2">
Expand Down
3 changes: 2 additions & 1 deletion themes/hexo/components/BlogPostCardInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Link from 'next/link'
import TagItemMini from './TagItemMini'
import TwikooCommentCount from '@/components/TwikooCommentCount'
import BLOG from '@/blog.config'
import { formatDateFmt } from '@/lib/formatDate'

/**
* 博客列表的文字内容
Expand Down Expand Up @@ -70,7 +71,7 @@ export const BlogPostCardInfo = ({ post, showPreview, showPageCover, showSummary
<div className="text-gray-400 justify-between flex">
{/* 日期 */}
<Link
href={`/archive#${post?.publishTime?.substr(0, 7)}`}
href={`/archive#${formatDateFmt(post?.publishDate, 'yyyy-MM')}`}
passHref
className="font-light menu-link cursor-pointer text-sm leading-4 mr-3">

Expand Down
3 changes: 2 additions & 1 deletion themes/hexo/components/PostHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useGlobal } from '@/lib/global'
import BLOG from '@/blog.config'
import NotionIcon from '@/components/NotionIcon'
import LazyImage from '@/components/LazyImage'
import { formatDateFmt } from '@/lib/formatDate'

export default function PostHeader({ post, siteInfo }) {
const { locale } = useGlobal()
Expand Down Expand Up @@ -42,7 +43,7 @@ export default function PostHeader({ post, siteInfo }) {
{post?.type !== 'Page' && (
<>
<Link
href={`/archive#${post?.publishTime?.substr(0, 7)}`}
href={`/archive#${formatDateFmt(post?.publishDate, 'yyyy-MM')}`}
passHref
className="pl-1 mr-2 cursor-pointer hover:underline">

Expand Down
3 changes: 2 additions & 1 deletion themes/matery/components/ArticleInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Link from 'next/link'
import { useGlobal } from '@/lib/global'
import TagItemMiddle from './TagItemMiddle'
import WordCount from './WordCount'
import { formatDateFmt } from '@/lib/formatDate'

export const ArticleInfo = (props) => {
const { post } = props
Expand All @@ -23,7 +24,7 @@ export const ArticleInfo = (props) => {
<div className='flex flex-wrap gap-3 mt-5 text-sm'>
{post?.type !== 'Page' && (<>
<Link
href={`/archive#${post?.publishTime?.substr(0, 7)}`}
href={`/archive#${formatDateFmt(post?.publishDate, 'yyyy-MM')}`}
passHref
className="cursor-pointer whitespace-nowrap">

Expand Down
3 changes: 2 additions & 1 deletion themes/matery/components/BlogPostCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import TagItemMini from './TagItemMini'
import CONFIG from '../config'
import TwikooCommentCount from '@/components/TwikooCommentCount'
import LazyImage from '@/components/LazyImage'
import { formatDateFmt } from '@/lib/formatDate'
// import Image from 'next/image'

const BlogPostCard = ({ index, post, showSummary, siteInfo }) => {
Expand Down Expand Up @@ -56,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?.publishTime?.substr(0, 7)}`}
href={`/archive#${formatDateFmt(post?.publishDate, 'yyyy-MM')}`}
passHref
className="font-light hover:underline cursor-pointer text-sm leading-4 mr-3">

Expand Down
3 changes: 2 additions & 1 deletion themes/next/components/ArticleDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import NotionPage from '@/components/NotionPage'
import CONFIG from '../config'
import NotionIcon from '@/components/NotionIcon'
import LazyImage from '@/components/LazyImage'
import { formatDateFmt } from '@/lib/formatDate'

/**
*
Expand Down Expand Up @@ -54,7 +55,7 @@ export default function ArticleDetail(props) {
<div className='flex flex-wrap justify-center'>
{post?.type !== 'Page' && (<>
<Link
href={`/archive#${post?.publishTime?.substr(0, 7)}`}
href={`/archive#${formatDateFmt(post?.publishDate, 'yyyy-MM')}`}
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">
Expand Down
3 changes: 2 additions & 1 deletion themes/next/components/BlogPostCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import CONFIG from '../config'
import NotionPage from '@/components/NotionPage'
import NotionIcon from '@/components/NotionIcon'
import TwikooCommentCount from '@/components/TwikooCommentCount'
import { formatDateFmt } from '@/lib/formatDate'

const BlogPostCard = ({ post, showSummary }) => {
const { locale } = useGlobal()
Expand Down Expand Up @@ -57,7 +58,7 @@ const BlogPostCard = ({ post, showSummary }) => {
</>
)}
<Link
href={`/archive#${post?.publishTime?.substr(0, 7)}`}
href={`/archive#${formatDateFmt(post?.publishDate, 'yyyy-MM')}`}
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}
Expand Down
3 changes: 2 additions & 1 deletion themes/simple/components/ArticleInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Link from 'next/link'
import { useGlobal } from '@/lib/global'
import CONFIG from '../config'
import BLOG from '@/blog.config'
import { formatDateFmt } from '@/lib/formatDate'

export const ArticleInfo = (props) => {
const { post } = props
Expand All @@ -28,7 +29,7 @@ export const ArticleInfo = (props) => {
{post?.type !== 'Page' && (<>
<span>{locale.COMMON.POST_TIME}:
<Link
href={`/archive#${post?.publishTime?.substr(0, 7)}`}
href={`/archive#${formatDateFmt(post?.publishDate, 'yyyy-MM')}`}
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}
Expand Down
3 changes: 2 additions & 1 deletion themes/simple/components/BlogItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import BLOG from '@/blog.config'
import Link from 'next/link'
import CONFIG from '../config'
import TwikooCommentCount from '@/components/TwikooCommentCount'
import { formatDateFmt } from '@/lib/formatDate'

export const BlogItem = props => {
const { post } = props
Expand All @@ -23,7 +24,7 @@ export const BlogItem = props => {
<div className='space-x-2'>
<span> <a href={CONFIG.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?.publishTime?.substr(0, 7)}`}>
<Link className='p-1 hover:text-red-400 transition-all duration-200' href={`/archive#${formatDateFmt(post?.publishDate, 'yyyy-MM')}`}>
<i className="fa-regular fa-clock" /> {post.date?.start_date || post.createdTime}
</Link>
</span>
Expand Down

0 comments on commit dffd709

Please sign in to comment.