Skip to content

Commit f7dc8d6

Browse files
committed
Hugo: stop using getJSON
I looked at https://discourse.gohugo.io/t/how-to-replace-the-data-getjson-with-resources-getremote-or-resources-get/52728/4 to learn a little about how to do it.
1 parent d050a10 commit f7dc8d6

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

website_and_docs/layouts/partials/previous-releases.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ <h2 class="modal-title" id="previous-releases-label">Previous Releases</h2>
2626
{{ $toReplace := printf "://%s@" $githubToken }}
2727
{{ $tokenInUrl := cond (eq $githubToken "") "://" $toReplace }}
2828
{{ $urlWithToken := replace $url "://" $tokenInUrl }}
29-
{{ $releases := getJSON $urlWithToken }}
29+
{{ $releasesJson := resources.GetRemote $urlWithToken }}
30+
{{ $releases := $releasesJson | transform.Unmarshal }}
3031
{{ range sort $releases "created_at" "desc" }}
3132
<!-- Expand / Collapse -->
3233
{{ $.Scratch.Set "counter" (add ($.Scratch.Get "counter") 1) }}

website_and_docs/layouts/shortcodes/gh-codeblock.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
{{ $tokenInUrl := cond (eq $githubToken "") "://" $toReplace }}
3636
{{ $apiUrlWithToken := replace $apiUrl "://" $tokenInUrl }}
3737

38-
{{ $apiResults := getJSON $apiUrlWithToken }}
38+
{{ $apiResultsJson := resources.GetRemote $apiUrlWithToken }}
39+
{{ $apiResults := $apiResultsJson | transform.Unmarshal }}
40+
3941
{{ $content := base64Decode $apiResults.content }}
4042
{{ $codeSnippet := $content }}
4143

website_and_docs/layouts/shortcodes/gh-contributors.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
{{ $tokenInUrl :=cond (eq $githubToken "") "://" $toReplace }}
2626
{{ $url := replace $url "://" $tokenInUrl }}
2727

28-
{{ range getJSON $url }}
28+
{{ $contributorJson := resources.GetRemote $url }}
29+
{{ $contributors := $contributorJson | transform.Unmarshal }}
30+
31+
{{ range $contributors }}
2932
<div style="padding: 10px;">
3033
<img
3134
src="{{.avatar_url}}"

website_and_docs/layouts/shortcodes/gh-user.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@
44
{{ $toReplace := printf "://%s@" $githubToken }}
55
{{ $tokenInUrl :=cond (eq $githubToken "") "://" $toReplace }}
66
{{ $url := replace $url "://" $tokenInUrl }}
7-
{{ $jsonUrl := getJSON $url }}
7+
{{ $userJson := resources.GetRemote $url }}
8+
{{ $user := $userJson | transform.Unmarshal }}
89

910
<div class="card text-center bg-transparent border-0 p-2 h-100" style="max-width: 12rem;">
10-
<img src="{{$jsonUrl.avatar_url}}" class="card-img-top mx-auto" alt="{{$jsonUrl.name}}" style="max-width: 122px;">
11+
<img src="{{$user.avatar_url}}" class="card-img-top mx-auto" alt="{{$user.name}}" style="max-width: 122px;">
1112
<div class="card-body pb-0 px-1">
1213
<p class="card-text m-0">
13-
{{$jsonUrl.name}}
14+
{{$user.name}}
1415
</p>
1516
</div>
1617
<div class="card-footer bg-transparent border-0 px-1">
1718
<p>
18-
<a href="{{$jsonUrl.html_url}}">@{{$jsonUrl.login}}</a>
19+
<a href="{{$user.html_url}}">@{{$user.login}}</a>
1920
</p>
2021
</div>
2122
</div>

0 commit comments

Comments
 (0)