I’m making nested getJSON calls and using range to get at the data therein, and am receiving errors that I can not figure for the life of me. Quite possible that I am missing something glaring since I’ve been up for ~40 hours, so I may just need a second pair of eyes here:
{{ $urlPre := "https://api.github.com" }}
{{ $git_user := "XXX" }}
{{ $user_json := getJSON $urlPre "/users/" $git_user "/repos" }}
{{ range $user_json }}
{{ if .name }}
name={{ .name }}
{{ $repo_json := getJSON $urlPre "/repos/" $git_user "/" .name }}
{{ range $repo_json }}
<a href="{{ .html_url }}">{{ .name }}</a> has {{ .watchers }}
{{ end }}
{{ end }}
{{ end }}
upon running hugo yields:
ERROR: 2015/11/10 template: partials/codelist.html:9:15: executing "partials/codelist.html" at <.html_url>: can't evaluate field html_url in type interface {} in partials/codelist.html
However the repo_json is properly set and does contain html_url. So I am at a loss. Yes, the below does the same I know, but I was using the above to test for future stuff such as looking of builds and download stats. Any ideas?
Well there are no KEYS returned it would appear. This looks to be a bug in Hugo. I ran the JSON output from the API call to GitHub through a JSON validator and it is valid. Unless I am missing something, this is a fault within Hugo?
I know this is an old post, but I’d like to thank @SchumacherFM for this code and ask a question about this: when I use a wrong user name on Github, their API returns an error, and Hugo reacts with:
ERROR 2020/02/11 09:56:19 Failed to get JSON resource "https://api.github.com/users/santa-clauz": Failed to retrieve remote file: Not Found
[That error occurs because santa-clauz doesn’t exist. That’s right guys, sorry about that]
My question, is how can I catch that without breaking everything? I want to display some error message, not have my site stop building just because some Github user was deleted…