Skip to content

Instantly share code, notes, and snippets.

@Rarst
Last active June 11, 2024 14:13
Show Gist options
  • Save Rarst/da20cdb3936fc5dcf349b4a5cab06f2f to your computer and use it in GitHub Desktop.
Save Rarst/da20cdb3936fc5dcf349b4a5cab06f2f to your computer and use it in GitHub Desktop.
Remote API example in Hugo static site build.
{{ with getJSON "https://noti.st/rarst.json" }}
<h3 class="text-left">Latest Talk</h3>
{{ $talks := (index .data 0).relationships.data }}
{{ $latest :=index $talks 0 }}
<a href="{{ $latest.links.self }}">
<img src="{{ $latest.attributes.image.src }}" alt="{{ $latest.attributes.title }}"
class="img-responsive" style="max-height: 210px;border: 1px solid #eee" loading="lazy"/>
</a>
{{ end }}
{{ with getJSON "https://api.github.com/users/Rarst/repos" }}
<h3 class="text-left">Top Projects</h3>
{{ $projects := sort (where . "fork" false) "stargazers_count" "desc" | first 3 }}
<div class="row text-left">
{{ range $projects }}
<div class="col-sm-4 col-md-12">
<a href="{{ .html_url }}">{{ replace .name "-" " " | title }}</a>
<span class="pull-right">★{{ .stargazers_count }}</span>
<p>{{ .description }}</p>
</div>
{{ end }}
</div>
{{ end }}
@dorneanu
Copy link

Wow! I din't even know this is possible. Thanks for sharing!

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