Skip to content

Instantly share code, notes, and snippets.

@macram
Last active September 13, 2025 14:44
Show Gist options
  • Select an option

  • Save macram/3992b578a19d08e87c09a071a184ffe3 to your computer and use it in GitHub Desktop.

Select an option

Save macram/3992b578a19d08e87c09a071a184ffe3 to your computer and use it in GitHub Desktop.
Hugo shortcode to show most played artists on Last.FM
{{ if .Get "period" }}
{{ if .Get "user" }}
{{ $apikey := "" }}
{{ $username := .Get "user" }}
{{ $baseUrl := "https://ws.audioscrobbler.com/2.0/?method=user.gettopartists&format=json" }}
{{ $period := .Get "period" }}
{{ $limit := .Get "limit" | default "5" }}
{{ $url := printf "%s%s%s%s%s%s%s%s%s" $baseUrl "&user=" $username "&api_key=" $apikey "&period=" $period "&limit=" $limit }}
{{ with resources.GetRemote $url | transform.Unmarshal }}
{{ range first 1 .topartists.artist }}<a href="{{ .url }}">{{ trim .name " " }}</a>{{ end }}
{{ if gt (int $limit) 2 }}
{{ $middleElements := after 1 .topartists.artist | first (sub (int $limit) 2) }}
{{ range $middleElements }}, <a href="{{ .url }}">{{ trim .name " " }}</a>{{ end }}
{{ range last 1 .topartists.artist }}y <a href="{{ .url }}">{{ trim .name " " }}</a>{{ end }}.
{{ end }}
{{ end }}
{{ end }}
{{ end }}
@macram
Copy link
Author

macram commented Sep 8, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment