feat: add ansible galaxy card shortcode

This commit is contained in:
Kevin Horst
2026-05-08 19:20:53 +02:00
parent da8ca782aa
commit 88863335fd
4 changed files with 231 additions and 1 deletions
+2
View File
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<svg fill="currentColor" viewBox="0 0 24 24" role="img" xmlns="http://www.w3.org/2000/svg"><path d="M10.617 11.473l4.686 3.695-3.102-7.662zM12 0C5.371 0 0 5.371 0 12s5.371 12 12 12 12-5.371 12-12S18.629 0 12 0zm5.797 17.305c-.011.471-.403.842-.875.83-.236 0-.416-.09-.664-.293l-6.19-5-2.079 5.203H6.191L11.438 5.44c.124-.314.427-.52.764-.506.326-.014.63.189.742.506l4.774 11.494c.045.111.08.234.08.348-.001.009-.001.009-.001.023z"/></svg>

After

Width:  |  Height:  |  Size: 478 B

+24 -1
View File
@@ -12,6 +12,14 @@
}
const platforms = {
"ansible-role": {
"results.0.download_count": "downloads",
"results.0.summary_fields.versions.0.name": "version",
},
"ansible-collection": {
download_count: "downloads",
"highest_version.version": "version",
},
github: {
full_name: "full_name",
description: "description",
@@ -49,12 +57,27 @@
},
};
const formatThousands = (value) =>
value == null ? value : Number(value).toLocaleString("en-US");
const processors = {
huggingface: {
description: (value) => value?.replace(/Dataset Card for .+?\s+Dataset Summary\s+/, "").trim() || value,
},
"ansible-role": {
"results.0.download_count": formatThousands,
},
"ansible-collection": {
download_count: formatThousands,
},
};
const getNested = (obj, path) =>
path.split(".").reduce((acc, key) => {
if (acc == null) return undefined;
return Array.isArray(acc) ? acc[Number(key)] : acc[key];
}, obj);
const platform = Object.keys(platforms).find((p) => repoId.startsWith(p)) || "github";
const mapping = platforms[platform];
@@ -77,7 +100,7 @@
Object.entries(mapping).forEach(([dataField, elementSuffix]) => {
const element = document.getElementById(`${repoId}-${elementSuffix}`);
if (element) {
let value = data[dataField];
let value = getNested(data, dataField);
if (processors[platform]?.[dataField]) {
value = processors[platform][dataField](value);
}