summaryrefslogtreecommitdiffstats
path: root/layouts/shortcodes/latest-release.html
blob: 33389c7e3c248197792d44c10867ae97300983a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{{- /*
  The latest release of a GitHub repository, read when the site builds so visitors never contact
  GitHub. Params: repo (owner/name), label. Prints nothing if GitHub cannot be reached.
  The key changes on every build: GetRemote's cache never expires by default.
  ponytail: each build leaves one small file in Hugo's cache; `hugo --gc` if that ever matters.
*/ -}}
{{- $url := printf "https://api.github.com/repos/%s/releases/latest" (.Get "repo") -}}
{{- with try (resources.GetRemote $url (dict "key" now.Unix)) -}}
  {{- with .Err -}}
    {{- warnf "latest-release: %s" . -}}
  {{- else with .Value -}}
    {{- with (. | transform.Unmarshal).tag_name -}}
<p class="cta-block__caption">{{ $.Get "label" }}: {{ strings.TrimPrefix "v" . }}</p>
    {{- end -}}
  {{- end -}}
{{- end -}}