Can I get information about my Github Gists?

I’m building a Hugo short code to fetch data from a Github API. I never realized that Hugo could build a SSG site with data content! This is great to know.

Oh yeah! I reverted my website to use Hugo because of how fast it is. Honestly, build tools probably shouldn’t be JS anymore.

I originally had a monorepo for my content, but I just figured to use some domain redirects to show the different sites.

References Used

Data Templates in Hugo

Shortcodes in Hugo

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{{ $githubUser := $.Params.githubUser }}

{{ $githubGists := getJSON "https://api.github.com/users/" $githubUser "/gists"}}
{{ range $i, $r := $githubGists }} {{ $descOfGist := $r.description }}

<div id="{{ $r.id }}">
  {{ if $descOfGist }}
  <p>Description: {{ $descOfGist }}</p>
  {{ else }}
  <p>No description</p>
  {{ end }}

  <p>Is public: {{ $r.public }}</p>

  <p>Created: {{ $r.created_at | time.Format ":date_long" }}</p>

  <p>Last Updated: {{ $r.updated_at | time.Format ":date_long" }}</p>

  <p><a href="{{ $r.html_url }}" target="_blank">Github Location</a></p>
</div>

<hr>

{{ end }}

Results of Shortcode Getting Gists

Worked out well I think! So this could show that one may build a whole ecommerce storefront with this?

2024 Update!

It turns out that getJSON is going to be deprecated soonish, so I was able to turn the shortcode into this!

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{{ $githubUser := $.Params.githubUser }}

{{ $data := dict }}

{{ $path := printf "https://api.github.com/users/%s/gists" $githubUser }}
{{ with resources.GetRemote $path  }}
  {{ with .Content | transform.Unmarshal }}
    {{ $data = . }}
  {{ end }}
{{ else }}
  {{ errorf "Unable to get global resource %q" $path }}
{{ end }}

{{ range $data }}
  <div id="{{ .id }}">
    {{ if .description }}
    <p>Description: {{ .description }}</p>
    {{ else }}
    <p>No description</p>
    {{ end }}

    <p>Is public: {{ .public }}</p>

    <p>Created: {{ .created_at | time.Format ":date_long" }}</p>

    <p>Last Updated: {{ .updated_at | time.Format ":date_long" }}</p>

    <p><a href="{{ .html_url }}" target="_blank">Github Location</a></p>
  </div>
{{ end }}

Output

Description: The Phonebook (JS style)

Is public: true

Created: April 26, 2022

Last Updated: April 26, 2022

Github Location

Description: Headspace Dot CSS Animation https://codepen.io/andrewgremlich/pen/mdrPmGr

Is public: true

Created: December 5, 2020

Last Updated: December 5, 2020

Github Location

Description: Advanced Search Modal for detailed data

Is public: true

Created: November 7, 2018

Last Updated: November 7, 2018

Github Location

Description: Detailed Dropdown. When some dropdowns aren't just enough, here's a detailed component dropdown for those dropdown needs

Is public: true

Created: November 5, 2018

Last Updated: November 6, 2018

Github Location

No description

Is public: true

Created: June 17, 2018

Last Updated: January 18, 2019

Github Location

Description: This is a file that shows a formatted phone number based upon certain regular expressions to target certain areas.

Is public: true

Created: June 15, 2018

Last Updated: June 15, 2018

Github Location

Description: Inheritance attempt with parent and grandparent with prototypes and objects.

Is public: true

Created: April 23, 2018

Last Updated: April 23, 2018

Github Location

Description: A close implementation of client-side routing

Is public: true

Created: April 18, 2018

Last Updated: April 19, 2018

Github Location

Description: The latest version of my ‘killer contract’ for web designers and developers

Is public: true

Created: June 28, 2017

Last Updated: July 1, 2017

Github Location

Description: Utilizes Web Components to make an menu-drawer for mobile devices. Primarily to be used with Progressive Web Apps.

Is public: true

Created: March 3, 2017

Last Updated: March 3, 2017

Github Location

Description: Shadow Dom example

Is public: true

Created: February 15, 2017

Last Updated: March 3, 2017

Github Location

Description: Code to see if an array of a sudoku number set is valid.

Is public: true

Created: October 19, 2016

Last Updated: October 19, 2016

Github Location