feat: add huggingface shortcode (#2376)

This commit is contained in:
ZhenShuo Leo
2025-07-29 04:28:54 +08:00
parent 550011ee58
commit 3ee9ed824f
2 changed files with 124 additions and 1 deletions

View File

@@ -36,6 +36,17 @@
stars_count: "stars_count",
forks_count: "forks_count",
},
huggingface: {
description: "description",
likes: "likes",
downloads: "downloads",
},
};
const processors = {
huggingface: {
description: (value) => value?.replace(/Dataset Card for .+?\s+Dataset Summary\s+/, "").trim() || value,
},
};
const platform = Object.keys(platforms).find((p) => repoId.startsWith(p)) || "github";
@@ -49,7 +60,13 @@
Object.entries(mapping).forEach(([dataField, elementSuffix]) => {
const element = document.getElementById(`${repoId}-${elementSuffix}`);
if (element) element.innerHTML = data[dataField];
if (element) {
let value = data[dataField];
if (processors[platform]?.[dataField]) {
value = processors[platform][dataField](value);
}
element.innerHTML = value;
}
});
} catch (error) {
console.error(error);