Merge pull request #4796 from janhq/fix/hub-desc-render

fix: hub model list desc render
This commit is contained in:
David 2025-03-11 15:29:03 +07:00 committed by GitHub
commit 3e6bccdc9c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 5 deletions

View File

@ -5,6 +5,7 @@ import Image from 'next/image'
import { ModelSource } from '@janhq/core'
import { DownloadIcon, FileJson } from 'lucide-react'
import rehypeRaw from 'rehype-raw'
import ModelLabel from '@/containers/ModelLabel'
@ -36,6 +37,7 @@ const ModelItem: React.FC<Props> = ({ model, onSelectedModel }) => {
<Markdown
className="md-short-desc line-clamp-3 max-w-full overflow-hidden font-light text-[hsla(var(--text-secondary))]"
components={markdownComponents}
rehypePlugins={[rehypeRaw]}
>
{extractDescription(model.metadata?.description) || '-'}
</Markdown>

View File

@ -7,12 +7,19 @@ export const extractDescription = (text?: string) => {
const normalizedText = removeYamlFrontMatter(text)
const overviewPattern = /(?:##\s*Overview\s*\n)([\s\S]*?)(?=\n\s*##|$)/
const matches = normalizedText?.match(overviewPattern)
if (matches && matches[1]) {
return matches[1].trim()
}
return normalizedText?.slice(0, 500).trim()
}
let extractedText =
matches && matches[1]
? matches[1].trim()
: normalizedText?.slice(0, 500).trim()
// Remove image markdown syntax ![alt text](image-url)
extractedText = extractedText?.replace(/!\[.*?\]\(.*?\)/g, '')
// Remove <img> HTML tags
extractedText = extractedText?.replace(/<img[^>]*>/g, '')
return extractedText
}
/**
* Remove YAML (HF metadata) front matter from content
* @param content