fix: render desc hub model list

This commit is contained in:
Faisal Amir 2025-03-11 15:13:23 +07:00
parent c000f75593
commit ba736d264b
2 changed files with 15 additions and 5 deletions

View File

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

View File

@ -7,12 +7,19 @@ export const extractDescription = (text?: string) => {
const normalizedText = removeYamlFrontMatter(text) const normalizedText = removeYamlFrontMatter(text)
const overviewPattern = /(?:##\s*Overview\s*\n)([\s\S]*?)(?=\n\s*##|$)/ const overviewPattern = /(?:##\s*Overview\s*\n)([\s\S]*?)(?=\n\s*##|$)/
const matches = normalizedText?.match(overviewPattern) const matches = normalizedText?.match(overviewPattern)
if (matches && matches[1]) { let extractedText =
return matches[1].trim() matches && matches[1]
} ? matches[1].trim()
return normalizedText?.slice(0, 500).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 * Remove YAML (HF metadata) front matter from content
* @param content * @param content