Skip to content

Commit

Permalink
tplimpl: Fix instagram shortcode panic on invalid ID
Browse files Browse the repository at this point in the history
Instagram doesn't return a valid JSON response when the requested ID is
invalid or not found.

Fixes gohugoio#3048
  • Loading branch information
moorereason committed Feb 17, 2017
1 parent 04a4a19 commit c08e812
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion tpl/tplimpl/template_embedded.go
Expand Up @@ -60,7 +60,7 @@ func (t *GoHTMLTemplate) EmbedShortcodes() {
{{ end }}`)
t.AddInternalShortcode("gist.html", `<script src="//gist.github.com/{{ index .Params 0 }}/{{ index .Params 1 }}.js{{if len .Params | eq 3 }}?file={{ index .Params 2 }}{{end}}"></script>`)
t.AddInternalShortcode("tweet.html", `{{ (getJSON "https://api.twitter.com/1/statuses/oembed.json?id=" (index .Params 0)).html | safeHTML }}`)
t.AddInternalShortcode("instagram.html", `{{ if len .Params | eq 2 }}{{ if eq (.Get 1) "hidecaption" }}{{ (getJSON "https://api.instagram.com/oembed/?url=https://instagram.com/p/" (index .Params 0) "/&hidecaption=1").html | safeHTML }}{{ end }}{{ else }}{{ (getJSON "https://api.instagram.com/oembed/?url=https://instagram.com/p/" (index .Params 0) "/&hidecaption=0").html | safeHTML }}{{ end }}`)
t.AddInternalShortcode("instagram.html", `{{ if len .Params | eq 2 }}{{ if eq (.Get 1) "hidecaption" }}{{ with getJSON "https://api.instagram.com/oembed/?url=https://instagram.com/p/" (index .Params 0) "/&hidecaption=1" }}{{ .html | safeHTML }}{{ end }}{{ end }}{{ else }}{{ with getJSON "https://api.instagram.com/oembed/?url=https://instagram.com/p/" (index .Params 0) "/&hidecaption=0" }}{{ .html | safeHTML }}{{ end }}{{ end }}`)
}

func (t *GoHTMLTemplate) EmbedTemplates() {
Expand Down

0 comments on commit c08e812

Please sign in to comment.