instagram.html 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. {{- $pc := .Page.Site.Config.Privacy.Instagram -}}
  2. {{- $sc := .Page.Site.Config.Services.Instagram -}}
  3. {{- if not $pc.Disable -}}
  4. {{- $id := .Get 0 -}}
  5. {{- $item := getJSON "https://api.instagram.com/oembed/?url=https://www.instagram.com/p/" $id "/&maxwidth=640&omitscript=true" -}}
  6. {{- $class1 := "__h_instagram" -}}
  7. {{- $class2 := "s_instagram_simple" -}}
  8. {{- $hideCaption := (eq (.Get 1) "hidecaption") -}}
  9. {{ with $item }}
  10. {{- $mediaURL := printf "https://instagram.com/p/%s/" $id | safeURL -}}
  11. {{- if not $sc.DisableInlineCSS -}}
  12. {{ template "__h_simple_instagram_css" $ }}
  13. {{- end -}}
  14. <div class="{{ $class1 }} {{ $class2 }} card" style="max-width: {{ $item.thumbnail_width }}px">
  15. <div class="card-header">
  16. <a href="{{ $item.author_url | safeURL }}" class="card-link">{{ $item.author_name }}</a>
  17. </div>
  18. <a href="{{ $mediaURL }}" 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>
  19. <div class="card-body">
  20. {{ if not $hideCaption }}<p class="card-text"><a href="{{ $item.author_url | safeURL }}" class="card-link">{{ $item.author_name }}</a> {{ $item.title}}</p>{{ end }}
  21. <a href="{{ $item.author_url | safeURL }}" class="card-link">View More on Instagram</a>
  22. </div>
  23. </div>
  24. {{ end }}
  25. {{- end -}}
  26. {{ define "__h_simple_instagram_css" }}
  27. {{ if not (.Page.Scratch.Get "__h_simple_instagram_css") }}
  28. {{/* Only include once */}}
  29. {{ .Page.Scratch.Set "__h_simple_instagram_css" true }}
  30. <style type="text/css">
  31. .__h_instagram.card {
  32. font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif;
  33. font-size: 14px;
  34. border: 1px solid rgb(219, 219, 219);
  35. padding: 0;
  36. margin-top: 30px;
  37. }
  38. .__h_instagram.card .card-header, .__h_instagram.card .card-body {
  39. padding: 10px 10px 10px;
  40. }
  41. .__h_instagram.card img {
  42. width: 100%;
  43. height: auto;
  44. }
  45. </style>
  46. {{ end }}
  47. {{ end }}{{- $pc := .Page.Site.Config.Privacy.Instagram -}}
  48. {{- if not $pc.Disable -}}
  49. {{- if $pc.Simple -}}
  50. {{ template "_internal/shortcodes/instagram_simple.html" . }}
  51. {{- else -}}
  52. {{ $id := .Get 0 }}
  53. {{ $hideCaption := cond (eq (.Get 1) "hidecaption") "1" "0" }}
  54. {{ with getJSON "https://api.instagram.com/oembed/?url=https://instagram.com/p/" $id "/&hidecaption=" $hideCaption }}{{ .html | safeHTML }}{{ end }}
  55. {{- end -}}
  56. {{- end -}}