diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2021-06-07 12:45:00 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2021-06-08 10:30:45 +0200 |
commit | 9b5debe4b820132759cfdf7bff7fe9c1ad0a6bb1 (patch) | |
tree | a202477925fc879db34375292ebe432b74d3acd7 /tpl/tplimpl/embedded/templates.autogen.go | |
parent | 12530519d8fb4513c9c18a6494099b7dff8e4fd4 (diff) |
Upgrade Instagram shortcode
Fixes #7879
Diffstat (limited to 'tpl/tplimpl/embedded/templates.autogen.go')
-rw-r--r-- | tpl/tplimpl/embedded/templates.autogen.go | 113 |
1 files changed, 70 insertions, 43 deletions
diff --git a/tpl/tplimpl/embedded/templates.autogen.go b/tpl/tplimpl/embedded/templates.autogen.go index e4cd69921..c8732a914 100644 --- a/tpl/tplimpl/embedded/templates.autogen.go +++ b/tpl/tplimpl/embedded/templates.autogen.go @@ -387,63 +387,90 @@ if (!doNotTrack) { {`shortcodes/gist.html`, `<script type="application/javascript" src="https://gist.github.com/{{ index .Params 0 }}/{{ index .Params 1 }}.js{{if len .Params | eq 3 }}?file={{ index .Params 2 }}{{end}}"></script> `}, {`shortcodes/highlight.html`, `{{ if len .Params | eq 2 }}{{ highlight (trim .Inner "\n\r") (.Get 0) (.Get 1) }}{{ else }}{{ highlight (trim .Inner "\n\r") (.Get 0) "" }}{{ end }}`}, - {`shortcodes/instagram.html`, `{{- $pc := .Page.Site.Config.Privacy.Instagram -}} + {`shortcodes/instagram.html`, `{{- $pc := site.Config.Privacy.Instagram -}} {{- if not $pc.Disable -}} -{{- if $pc.Simple -}} -{{ template "_internal/shortcodes/instagram_simple.html" . }} -{{- else -}} -{{ $id := .Get 0 }} -{{ $hideCaption := cond (eq (.Get 1) "hidecaption") "1" "0" }} -{{ with getJSON "https://api.instagram.com/oembed/?url=https://instagram.com/p/" $id "/&hidecaption=" $hideCaption }}{{ .html | safeHTML }}{{ end }} -{{- end -}} + {{ $accessToken := site.Config.Services.Instagram.AccessToken }} + {{- if not $accessToken -}} + {{- erroridf "err-missing-instagram-accesstoken" "instagram shortcode: Missing config value for services.instagram.accessToken. This can be set in config.toml, but it is recommended to configure this via the HUGO_SERVICES_INSTAGRAM_ACCESSTOKEN OS environment variable. If you are using a Client Access Token, remember that you must combine it with your App ID using a pipe symbol (<APPID>|<CLIENTTOKEN>) otherwise the request will fail." -}} + {{- else -}} + {{- if $pc.Simple -}} + {{ template "_internal/shortcodes/instagram_simple.html" . }} + {{- else -}} + {{ $id := .Get 0 }} + {{ $hideCaption := cond (eq (.Get 1) "hidecaption") "1" "0" }} + {{ $headers := dict "Authorization" (printf "Bearer %s" $accessToken) }} + {{ with getJSON "https://graph.facebook.com/v8.0/instagram_oembed/?url=https://instagram.com/p/" $id "/&hidecaption=" $hideCaption $headers }} + {{ .html | safeHTML }} + {{ end }} + {{- end -}} + {{- end -}} {{- end -}}`}, {`shortcodes/instagram_simple.html`, `{{- $pc := .Page.Site.Config.Privacy.Instagram -}} {{- $sc := .Page.Site.Config.Services.Instagram -}} {{- if not $pc.Disable -}} -{{- $id := .Get 0 -}} -{{- $item := getJSON "https://api.instagram.com/oembed/?url=https://www.instagram.com/p/" $id "/&maxwidth=640&omitscript=true" -}} -{{- $class1 := "__h_instagram" -}} -{{- $class2 := "s_instagram_simple" -}} -{{- $hideCaption := (eq (.Get 1) "hidecaption") -}} -{{ with $item }} -{{- $mediaURL := printf "https://instagram.com/p/%s/" $id | safeURL -}} -{{- if not $sc.DisableInlineCSS -}} -{{ template "__h_simple_instagram_css" $ }} -{{- end -}} -<div class="{{ $class1 }} {{ $class2 }} card" style="max-width: {{ $item.thumbnail_width }}px"> - <div class="card-header"> - <a href="{{ $item.author_url | safeURL }}" class="card-link">{{ $item.author_name }}</a> - </div> - <a href="{{ $mediaURL }}" rel="noopener" target="_blank"><img class="card-img-top img-fluid" src="{{ $item.thumbnail_url }}" width="{{ $item.thumbnail_width }}" height="{{ $item.thumbnail_height }}" alt="Instagram Image"></a> - <div class="card-body"> - {{ if not $hideCaption }}<p class="card-text"><a href="{{ $item.author_url | safeURL }}" class="card-link">{{ $item.author_name }}</a> {{ $item.title}}</p>{{ end }} - <a href="{{ $item.author_url | safeURL }}" class="card-link">View More on Instagram</a> - </div> -</div> -{{ end }} + {{ $accessToken := site.Config.Services.Instagram.AccessToken }} + {{- if not $accessToken -}} + {{- erroridf "err-missing-instagram-accesstoken" "instagram shortcode: Missing config value for services.instagram.accessToken. This can be set in config.toml, but it is recommended to configure this via the HUGO_SERVICES_INSTAGRAM_ACCESSTOKEN OS environment variable. If you are using a Client Access Token, remember that you must combine it with your App ID using a pipe symbol (<APPID>|<CLIENTTOKEN>) otherwise the request will fail." -}} + {{- else -}} + {{- $id := .Get 0 -}} + {{- $headers := dict "Authorization" (printf "Bearer %s" $accessToken) -}} + {{- $item := getJSON "https://graph.facebook.com/v8.0/instagram_oembed/?url=https://instagram.com/p/" $id "/&maxwidth=640&omitscript=true" $headers -}} + {{- $class1 := "__h_instagram" -}} + {{- $class2 := "s_instagram_simple" -}} + {{- $hideCaption := (eq (.Get 1) "hidecaption") -}} + {{ with $item }} + {{- $mediaURL := printf "https://instagram.com/p/%s/" $id | safeURL -}} + {{- if not $sc.DisableInlineCSS -}} + {{ template "__h_simple_instagram_css" $ }} + {{- end -}} + <div class="{{ $class1 }} {{ $class2 }} card" style="max-width: {{ $item.thumbnail_width }}px"> + <div class="card-header"> + <a href="{{ $item.author_url | safeURL }}" class="card-link"> + {{ $item.author_name }} + </a> + </div> + <a href="{{ $mediaURL }}" rel="noopener" target="_blank"> + <img class="card-img-top img-fluid" src="{{ $item.thumbnail_url }}" width="{{ $item.thumbnail_width }}" height="{{ $item.thumbnail_height }}" alt="Instagram Image"> + </a> + <div class="card-body"> + {{ if not $hideCaption }} + <p class="card-text"> + <a href="{{ $item.author_url | safeURL }}" class="card-link"> + {{ $item.author_name }} + </a> + {{ $item.title}} + </p> + {{ end }} + <a href="{{ $item.author_url | safeURL }}" class="card-link"> + View More on Instagram + </a> + </div> + </div> + {{ end }} + {{- end -}} {{- end -}} {{ define "__h_simple_instagram_css" }} -{{ if not (.Page.Scratch.Get "__h_simple_instagram_css") }} -{{/* Only include once */}} -{{ .Page.Scratch.Set "__h_simple_instagram_css" true }} -<style type="text/css"> - .__h_instagram.card { + {{ if not (.Page.Scratch.Get "__h_simple_instagram_css") }} + {{/* Only include once */}} + {{ .Page.Scratch.Set "__h_simple_instagram_css" true }} + <style type="text/css"> + .__h_instagram.card { font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif; font-size: 14px; border: 1px solid rgb(219, 219, 219); padding: 0; - margin-top: 30px; - } - .__h_instagram.card .card-header, .__h_instagram.card .card-body { + margin-top: 30px; + } + .__h_instagram.card .card-header, .__h_instagram.card .card-body { padding: 10px 10px 10px; - } - .__h_instagram.card img { + } + .__h_instagram.card img { width: 100%; - height: auto; - } -</style> -{{ end }} + height: auto; + } + </style> + {{ end }} {{ end }}`}, {`shortcodes/param.html`, `{{- $name := (.Get 0) -}} {{- with $name -}} |