{{- $role := .Get "role" -}} {{- $collection := .Get "collection" -}} {{- $apiURL := "" -}} {{- $repoLink := "" -}} {{- $type := "" -}} {{- $namespace := "" -}} {{- $name := "" -}} {{- if $role -}} {{- $parts := split $role "." -}} {{- $namespace = index $parts 0 -}} {{- $name = index $parts 1 -}} {{- $apiURL = print "https://galaxy.ansible.com/api/v1/roles/?owner__username=" $namespace "&name=" $name -}} {{- $repoLink = print "https://galaxy.ansible.com/ui/standalone/roles/" $namespace "/" $name "/" -}} {{- $type = "role" -}} {{- else if $collection -}} {{- $parts := split $collection "." -}} {{- $namespace = index $parts 0 -}} {{- $name = index $parts 1 -}} {{- $apiURL = print "https://galaxy.ansible.com/api/v3/plugin/ansible/content/published/collections/index/" $namespace "/" $name "/" -}} {{- $repoLink = print "https://galaxy.ansible.com/ui/repo/published/" $namespace "/" $name "/" -}} {{- $type = "collection" -}} {{- end -}} {{ $id := delimit (slice "ansible" (partial "functions/uid.html" .)) "-" }} {{- $title := "" -}} {{- $description := "" -}} {{- $downloads := 0 -}} {{- $version := "" -}} {{- $tags := slice -}} {{- $license := "" -}} {{- $dataAvailable := false -}} {{- /* Formats an integer with comma thousand separators (lang.NumFmt is unavailable in this template context). */ -}} {{- define "_format-int" -}} {{- $n := printf "%d" (int .) -}} {{- $out := "" -}} {{- $len := len $n -}} {{- range $i := seq $len -}} {{- $idx := sub $i 1 -}} {{- $c := substr $n $idx 1 -}} {{- if and (gt $idx 0) (eq (mod (sub $len $idx) 3) 0) -}} {{- $out = print $out "," $c -}} {{- else -}} {{- $out = print $out $c -}} {{- end -}} {{- end -}} {{- $out -}} {{- end -}} {{- with try (resources.GetRemote $apiURL) -}} {{- with .Err -}} {{- warnf "ansible shortcode: failed to fetch remote resource from %q: %s" $apiURL $.Position -}} {{- else with .Value -}} {{- $resp := . | transform.Unmarshal -}} {{- if eq $type "role" -}} {{- with index ($resp.results | default slice) 0 -}} {{- $title = print $namespace "." .name -}} {{- $description = .description -}} {{- $downloads = .download_count -}} {{- with .summary_fields -}} {{- with index (.versions | default slice) 0 -}} {{- $version = .name -}} {{- end -}} {{- $tags = .tags -}} {{- end -}} {{- $dataAvailable = true -}} {{- end -}} {{- else if eq $type "collection" -}} {{- $title = print $namespace "." $name -}} {{- $downloads = $resp.download_count -}} {{- with $resp.highest_version -}} {{- $version = .version -}} {{- end -}} {{- if $version -}} {{- $versionURL := print $apiURL "versions/" $version "/" -}} {{- with try (resources.GetRemote $versionURL) -}} {{- with .Value -}} {{- $verResp := . | transform.Unmarshal -}} {{- with $verResp.metadata -}} {{- $description = .description -}} {{- $tags = .tags -}} {{- with .license -}} {{- $license = index . 0 -}} {{- end -}} {{- end -}} {{- end -}} {{- end -}} {{- end -}} {{- $dataAvailable = true -}} {{- end -}} {{- else -}} {{- warnf "ansible shortcode: unable to get remote resource from %q: %s" $apiURL $.Position -}} {{- end -}} {{- end -}} {{- if $dataAvailable -}}
{{- else if $apiURL -}} {{ warnf "ansible shortcode: unable to fetch %q: %s" $apiURL .Position }} {{- end -}}