feat: display reading time on post card
This commit is contained in:
@@ -102,30 +102,39 @@ const PostCard = ({
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{(!!post.metadata?.content?.tags?.[1] ||
|
||||
post.stat?.viewDetailCount) && (
|
||||
<div className="xlog-post-meta text-zinc-400 space-x-2 flex items-center">
|
||||
{!!post.metadata?.content?.tags?.[1] && (
|
||||
<span className="xlog-post-tags space-x-1 truncate min-w-0">
|
||||
<span
|
||||
className="hover:text-zinc-600"
|
||||
onClick={(e) => {
|
||||
e.preventDefault()
|
||||
router.push(`/tag/${post.metadata?.content?.tags?.[1]}`)
|
||||
}}
|
||||
>
|
||||
#{post.metadata?.content?.tags?.[1]}
|
||||
</span>
|
||||
<div className="xlog-post-meta text-zinc-400 space-x-2 flex items-center">
|
||||
{!!post.metadata?.content?.tags?.[1] && (
|
||||
<span
|
||||
className="xlog-post-tags hover:text-zinc-600 inline-flex items-center"
|
||||
onClick={(e) => {
|
||||
e.preventDefault()
|
||||
router.push(`/tag/${post.metadata?.content?.tags?.[1]}`)
|
||||
}}
|
||||
>
|
||||
<i className="icon-[mingcute--tag-line] mr-[2px]" />
|
||||
{post.metadata?.content?.tags?.[1]}
|
||||
</span>
|
||||
)}
|
||||
{!post.stat?.viewDetailCount && (
|
||||
<span className="xlog-post-word-count inline-flex items-center">
|
||||
<i className="icon-[mingcute--time-line] mr-[2px]" />
|
||||
<span
|
||||
style={{
|
||||
wordSpacing: "-.2ch",
|
||||
}}
|
||||
>
|
||||
{post.metadata?.content?.readingTime}{" "}
|
||||
{t(post.metadata?.content?.readingTime === 1 ? "min" : "mins")}
|
||||
</span>
|
||||
)}
|
||||
{!!post.stat?.viewDetailCount && (
|
||||
<span className="xlog-post-views inline-flex items-center">
|
||||
<i className="icon-[mingcute--eye-line] mr-[2px]" />
|
||||
<span>{post.stat?.viewDetailCount}</span>
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</span>
|
||||
)}
|
||||
{!!post.stat?.viewDetailCount && (
|
||||
<span className="xlog-post-views inline-flex items-center">
|
||||
<i className="icon-[mingcute--eye-line] mr-[2px]" />
|
||||
<span>{post.stat?.viewDetailCount}</span>
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center space-x-1 text-xs sm:text-sm overflow-hidden">
|
||||
<CharacterFloatCard siteId={character?.handle}>
|
||||
<span
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { CharacterEntity, NoteEntity } from "crossbell"
|
||||
import { nanoid } from "nanoid"
|
||||
import removeMarkdown from "remove-markdown"
|
||||
|
||||
import { SCORE_API_DOMAIN, SITE_URL } from "~/lib/env"
|
||||
import { toCid, toGateway } from "~/lib/ipfs-parser"
|
||||
@@ -71,6 +72,13 @@ export const expandCrossbellNote = async ({
|
||||
)?.value,
|
||||
)
|
||||
|
||||
expandedNote.metadata.content.readingTime = expandedNote.metadata.content
|
||||
.content
|
||||
? Math.round(
|
||||
removeMarkdown(expandedNote.metadata.content.content).length / 400,
|
||||
) // TODO
|
||||
: 0
|
||||
|
||||
if (useStat) {
|
||||
if ((note as any).stat?.viewDetailCount) {
|
||||
expandedNote.metadata.content.views = (note as any).stat
|
||||
|
||||
@@ -93,5 +93,7 @@
|
||||
"Add to playlist": "添加到播放列表",
|
||||
"Share Modal": "分享到...",
|
||||
"Share": "分享",
|
||||
"Share Message": "嘿,我发现了一篇宝藏文章「{{title}}」哩,快来看看吧!"
|
||||
"Share Message": "嘿,我发现了一篇宝藏文章「{{title}}」哩,快来看看吧!",
|
||||
"mins": "分钟",
|
||||
"min": "分钟"
|
||||
}
|
||||
|
||||
@@ -88,6 +88,7 @@ export type ExpandedNote = NoteEntity & {
|
||||
}
|
||||
contentHTML?: string
|
||||
disableAISummary?: boolean
|
||||
readingTime?: number
|
||||
}
|
||||
}
|
||||
stat?: {
|
||||
|
||||
@@ -72,13 +72,7 @@ export type MarkdownEnv = {
|
||||
export type Rendered = {
|
||||
contentHTML: string
|
||||
element?: ReactElement
|
||||
excerpt: string
|
||||
frontMatter: Record<string, any>
|
||||
cover: string
|
||||
audio: string
|
||||
toc: TocResult | null
|
||||
tree: Root | null
|
||||
}
|
||||
} & Omit<MarkdownEnv, "__internal">
|
||||
|
||||
refractor.alias("html", ["svelte", "vue"])
|
||||
refractor.register(tsx)
|
||||
|
||||
@@ -118,10 +118,7 @@ const getOriginalSummary = async (cid: string, lang: string) => {
|
||||
}
|
||||
|
||||
const res = await chain.call({
|
||||
input_document: removeMarkdown(content, {
|
||||
useImgAltText: true,
|
||||
gfm: true,
|
||||
}),
|
||||
input_document: removeMarkdown(content),
|
||||
})
|
||||
|
||||
console.timeEnd(`fetching summary ${cid}, ${lang}`)
|
||||
|
||||
Reference in New Issue
Block a user