Skip to content

Commit 50a7735

Browse files
committed
feat: post outdate info
Signed-off-by: Innei <[email protected]>
1 parent 78efb88 commit 50a7735

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

src/app/posts/(post-detail)/[category]/[slug]/page.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { Markdown } from '~/components/ui/markdown'
1212
import { PostActionAside } from '~/components/widgets/post/PostActionAside'
1313
import { PostCopyright } from '~/components/widgets/post/PostCopyright'
1414
import { PostMetaBar } from '~/components/widgets/post/PostMetaBar'
15+
import { PostOutdate } from '~/components/widgets/post/PostOutdate'
1516
import { PostRelated } from '~/components/widgets/post/PostRelated'
1617
import { SubscribeBell } from '~/components/widgets/subscribe/SubscribeBell'
1718
import { TocAside } from '~/components/widgets/toc'
@@ -43,6 +44,8 @@ const PostPage = () => {
4344
<PostMetaBarInternal className="mb-8 justify-center" />
4445

4546
<XLogSummaryForPost />
47+
48+
<PostOutdate />
4649
</header>
4750
<WrappedElementProvider>
4851
<PostMarkdownImageRecordProvider>

src/components/hoc/with-no-ssr.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const withNoSSR = <P,>(
77
): FC<PropsWithChildren<P>> => {
88
return (props: PropsWithChildren<P>) => {
99
const isClient = useIsClientTransition()
10-
if (!isClient) return props.children ?? null
10+
if (!isClient) return null
1111
// @ts-ignore
1212
return <Component {...props} />
1313
}

src/components/layout/footer/GatewayCount.tsx

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
'use client'
22

33
import { useOnlineCount } from '~/atoms'
4-
import { withNoSSR } from '~/components/hoc/with-no-ssr'
54
import { FloatPopover } from '~/components/ui/float-popover'
65

7-
export const GatewayCount = withNoSSR(() => {
6+
export const GatewayCount = () => {
87
return (
9-
<FloatPopover TriggerComponent={GatewayCountTrigger} type="tooltip">
8+
<FloatPopover
9+
as="span"
10+
TriggerComponent={GatewayCountTrigger}
11+
type="tooltip"
12+
>
1013
<div className="space-y-2 leading-relaxed">
1114
<p className="flex items-center space-x-1 opacity-80">
1215
<i className="icon-[mingcute--question-line]" />
@@ -23,7 +26,7 @@ export const GatewayCount = withNoSSR(() => {
2326
</div>
2427
</FloatPopover>
2528
)
26-
})
29+
}
2730
const GatewayCountTrigger = () => {
2831
const count = useOnlineCount()
2932
return <span>正在被 {count} 人看爆</span>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import dayjs from 'dayjs'
2+
3+
import { Banner } from '~/components/ui/banner'
4+
import { RelativeTime } from '~/components/ui/relative-time'
5+
import { useCurrentPostDataSelector } from '~/providers/post/CurrentPostDataProvider'
6+
7+
export const PostOutdate = () => {
8+
const time = useCurrentPostDataSelector((s) => s?.modified)
9+
if (!time) {
10+
return null
11+
}
12+
return dayjs().diff(dayjs(time), 'day') > 60 ? (
13+
<Banner type="warning" className="mb-10">
14+
<span className="leading-[1.8]">
15+
这篇文章上次修改于 <RelativeTime date={time} />
16+
,可能部分内容已经不适用,如有疑问可询问作者。
17+
</span>
18+
</Banner>
19+
) : null
20+
}

0 commit comments

Comments
 (0)