Contents

More Rabbit Holes

Ooh, shiny!

Static-Site Dynamism

I’m currently laying out some structured lessons describing HashiCorp operations, and I find myself in need of a dead-simple web site generator, for illustrative purposes.

Naturally, I turn to Hugo.

In doing a bit of thinking and reading, I’ve discovered the getJson shortlink. And that means that a call like {{ $profile := getJSON "https://api.github.com/users/cpilson" }} should resolve below:

{{ $profile := getJSON “https://api.github.com/users/cpilson" }}

Why didn’t this work? Ah, yes. We won’t know what to do with the JSON response (yet). In Hugo, the simplest approach in my mind would be to leverage the notion of shortcodes, written as an HTML template:

<!-- githubprofile.html - provides a shortlink that can be invoked to show GitHub profile information -->
<div class="githubprofile" style="display: flex; background-color: cornsilk;">
  {{ $url := .Get "url" }}
  {{ $user := .Get "user" }}
  {{ $profile := getJSON $url $user }}
  <div>
    <div style="display: flex;">
      <a href="{{$profile.html_url}}" target="_blank">
        <img src="{{$profile.avatar_url}}" alt="Avatar of {{$profile.name}}" title="Avatar of {{$profile.name}}"
          width="144px">
      </a>
      <div style="margin-left: 1rem;">
        <a href="{{ $profile.html_url }}" target="_blank">{{ $profile.name }} ({{ $profile.login}})</a>
        <br />
        <span style="margin-top: 2rem;">Bio: {{$profile.bio}}</span>
      </div>
    </div>
  </div>
</div>
<div class="clear"></div>

and we can invoke it thus: {{< githubprofile url="https://api.github.com/users/" user="cpilson" >}}

Avatar of Chris Pilson
Chris Pilson (cpilson)
Bio: Moved to GitLab July 2020; private projects. I am passionate about building technologies and products that empower and connect people.