Show a Hugging Face repository's model card on the mirror page

Opening a repository shows its model card, rendered from markdown, with
its base model, license and languages above it; the listing names each
repository's base model and license under its name. The card is a
stranger's text: raw HTML and dangerous links are dropped, images are
shown as links rather than loaded, and relative links point into the
repository.

Adds github.com/yuin/goldmark for the markdown.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ilker ManapandClaude Opus 5.5 committed 2026-09-28 22:03:19 +02:00
1 parent 02fa639657
commit 3fea39feb9
10 files changed
+375 -27

No files matched your search

+17
View File
@@ -97,3 +97,20 @@ func TestAnAdapterIsNotListedAsAModel(t *testing.T) {
t.Errorf("adapters should be left out and small models kept: %s", body)
}
}
func TestARepositoryShowsItsCard(t *testing.T) {
reg := &fakeRegistry{repo: hf.Repo{
ID: "Qwen/X-GGUF", Revision: "abc123def456", License: "apache-2.0",
BaseModel: []string{"Qwen/X"}, Card: "# X\n\nA **small** model. See [the license](LICENSE).",
Files: []hf.File{{Path: "x.gguf", Bytes: 10}},
}}
body := mirrorGet(t, mirrorPageLlama(t, MirrorDeps{Mirror: &fakeMirror{}, Registry: reg}),
"/admin/mirror?repo=Qwen/X-GGUF").Body.String()
for _, want := range []string{"<strong>small</strong>", "license apache-2.0", "<code>Qwen/X</code>",
`href="https://huggingface.co/Qwen/X-GGUF/blob/abc123def456/LICENSE"`,
`href="https://huggingface.co/Qwen/X-GGUF"`} {
if !strings.Contains(body, want) {
t.Errorf("missing %s", want)
}
}
}