diff --git a/assets/js/fetch-repo.js b/assets/js/fetch-repo.js index 0ea2bf67..61bedfd0 100644 --- a/assets/js/fetch-repo.js +++ b/assets/js/fetch-repo.js @@ -12,14 +12,6 @@ } 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", @@ -57,27 +49,12 @@ }, }; - 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]; @@ -100,7 +77,7 @@ Object.entries(mapping).forEach(([dataField, elementSuffix]) => { const element = document.getElementById(`${repoId}-${elementSuffix}`); if (element) { - let value = getNested(data, dataField); + let value = data[dataField]; if (processors[platform]?.[dataField]) { value = processors[platform][dataField](value); } diff --git a/exampleSite/content/docs/shortcodes/index.md b/exampleSite/content/docs/shortcodes/index.md index af0a381e..f97cdd7f 100644 --- a/exampleSite/content/docs/shortcodes/index.md +++ b/exampleSite/content/docs/shortcodes/index.md @@ -200,6 +200,8 @@ The alert sign (`+` or `-`) is optional to control whether the admonition is fol Set exactly one of `role` or `collection` per call. +All card values are fetched at build time via Hugo's `resources.GetRemote`. Galaxy does not allow cross-origin requests, so the card is not refreshed in the browser — rebuild the site to update the values. + **Example 1: Role** ```md diff --git a/layouts/shortcodes/ansible.html b/layouts/shortcodes/ansible.html index 99c5306a..2fbf042d 100644 --- a/layouts/shortcodes/ansible.html +++ b/layouts/shortcodes/ansible.html @@ -22,7 +22,7 @@ {{- $type = "collection" -}} {{- end -}} -{{ $id := delimit (slice "ansible" $type (partial "functions/uid.html" .)) "-" }} +{{ $id := delimit (slice "ansible" (partial "functions/uid.html" .)) "-" }} {{- $title := "" -}} {{- $description := "" -}} @@ -124,7 +124,7 @@ {{ partial "icon.html" "download" }} -