feat: add reading time calculation to news detail page

This commit is contained in:
Ardeman
2025-03-08 15:34:38 +08:00
parent be63337024
commit 6e858f1860
3 changed files with 20 additions and 1 deletions
+4 -1
View File
@@ -1,4 +1,5 @@
import htmlParse from 'html-react-parser'
import { useReadingTime } from 'react-hook-reading-time'
import { useRouteLoaderData } from 'react-router'
import type { TTagResponse } from '~/apis/common/get-tags'
@@ -19,6 +20,8 @@ export const NewsDetailPage = () => {
const { title, content, featured_image, slug, author, live_at, tags } =
newsDetailData || {}
const { text } = useReadingTime(content || '')
return (
<div className="sm-max:mx-5 relative">
<Card>
@@ -45,7 +48,7 @@ export const NewsDetailPage = () => {
<p className="flex gap-1 text-sm">
<span>{live_at && `${formatDate(live_at)}`}</span>
<span>·</span>
<span>5 min read</span>
<span>{text}</span>
</p>
</div>
</div>