hero.html 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. {{ $ := .root }}
  2. {{ $page := .page }}
  3. {{ $bg := $page.Params.design.background }}
  4. {{ if $page.Params.hero_media }}
  5. <div class="row">
  6. <div class="col-12 col-md-6 text-center text-md-left">
  7. {{ end }}
  8. {{ with $page.Title }}
  9. <h1 class="hero-title">{{ . | markdownify }}</h1>
  10. {{ end }}
  11. {{ with $page.Content }}
  12. <div class="hero-lead">{{ . }}</div>
  13. {{ end }}
  14. {{/* Call-to-action link */}}
  15. {{ if $page.Params.cta.url }}
  16. {{ $pack := or $page.Params.cta.icon_pack "fas" }}
  17. {{ $pack_prefix := $pack }}
  18. {{ if in (slice "fab" "fas" "far" "fal") $pack }}
  19. {{ $pack_prefix = "fa" }}
  20. {{ end }}
  21. {{ $link := $page.Params.cta.url }}
  22. {{ $scheme := (urls.Parse $link).Scheme }}
  23. {{ $target := "" }}
  24. {{ if not $scheme }}
  25. {{ $link = $link | relLangURL }}
  26. {{ else if in (slice "http" "https") $scheme }}
  27. {{ $target = "target=\"_blank\" rel=\"noopener\"" }}
  28. {{ end }}
  29. <p class="cta-btns">
  30. <a href="{{ $link | safeURL }}" {{ $target | safeHTMLAttr }} class="btn {{if $bg.text_color_light}}btn-light{{else}}btn-primary{{end}} btn-lg mb-md-1">{{ if $page.Params.cta.icon }}<i class="{{ $pack }} {{ $pack_prefix }}-{{ $page.Params.cta.icon }} pr-1" aria-hidden="true"></i>{{end}}{{ $page.Params.cta.label | markdownify | emojify | safeHTML }}</a>
  31. {{/* Alternative Call-to-action link */}}
  32. {{ if $page.Params.cta_alt.url }}
  33. {{ $link := $page.Params.cta_alt.url }}
  34. {{ $scheme := (urls.Parse $link).Scheme }}
  35. {{ $target := "" }}
  36. {{ if not $scheme }}
  37. {{ $link = $link | relLangURL }}
  38. {{ else if in (slice "http" "https") $scheme }}
  39. {{ $target = "target=\"_blank\" rel=\"noopener\"" }}
  40. {{ end }}
  41. <a href="{{ $link | safeURL }}" {{ $target | safeHTMLAttr }} class="hero-cta-alt btn-lg pl-md-4">{{ $page.Params.cta_alt.label | markdownify | emojify | safeHTML }} <i class="fas fa-angle-right"></i></a>
  42. {{ end }}
  43. </p>
  44. {{ end }}
  45. {{/* Call-to-action note */}}
  46. {{ with $page.Params.cta_note }}
  47. <p class="hero-note text-muted mb-3 mb-md-1">
  48. {{ .label | markdownify | emojify | safeHTML }}
  49. </p>
  50. {{ end }}
  51. {{/* Hero image */}}
  52. {{ if $page.Params.hero_media }}
  53. </div>
  54. <div class="col-12 mx-auto col-md-6 {{if $page.Params.design.flip}}order-md-first{{end}} hero-media">
  55. {{- $image := ($page.Parent.Resources.ByType "image").GetMatch $page.Params.hero_media -}}
  56. {{- if not $image -}}
  57. {{- $image = resources.Get (path.Join "media" $page.Params.hero_media) -}}
  58. {{- end -}}
  59. {{ if $image }}
  60. {{ $isSVG := eq $image.MediaType.SubType "svg" }}
  61. {{ if $isSVG -}}
  62. <img src="{{ $image.RelPermalink }}" alt="{{ $page.Title }}">
  63. {{- else }}
  64. {{ $legacy_img := $image.Resize "400x" }}
  65. {{ $img_src := "" }}
  66. {{ $img_src_set := slice }}
  67. {{ $widths := slice 1200 800 400 }}
  68. {{ range $widths }}
  69. {{ $src_link := ($image.Resize (printf "%dx" .)).RelPermalink }}
  70. {{ if eq $img_src "" }}
  71. {{ $img_src = $src_link }}
  72. {{ end }}
  73. {{ $img_src_set = $img_src_set | append (printf "%s %dw" $src_link .) }}
  74. {{ end }}
  75. {{ $img_src_set = delimit $img_src_set "," }}
  76. <img src="{{ $legacy_img.RelPermalink }}" srcset="{{ $img_src_set }}" width="{{ $image.Width }}" height="{{ $image.Height }}" alt="{{ $page.Title }}">
  77. {{ end }}
  78. {{ end }}
  79. </div>
  80. </div>
  81. {{ end }}