-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #7879
- Loading branch information
Showing
7 changed files
with
158 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
{{- $pc := .Page.Site.Config.Privacy.Instagram -}} | ||
{{- $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 -}} |
89 changes: 54 additions & 35 deletions
89
tpl/tplimpl/embedded/templates/shortcodes/instagram_simple.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,67 @@ | ||
{{- $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 }} |