hero.html 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 order-md-1 text-center text-md-left">
  7. {{ end }}
  8. <h1 class="hero-title">
  9. {{ with $page.Title }}{{ . | markdownify }}{{ end }}
  10. </h1>
  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-3 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 order-md-2 hero-media">
  55. {{ $image := $page.Parent.Resources.GetMatch $page.Params.hero_media }}
  56. {{ if $image }}
  57. {{ $legacy_img := $image.Resize "400x" }}
  58. {{ $img_src := "" }}
  59. {{ $img_src_set := slice }}
  60. {{ $widths := slice 1200 800 400 }}
  61. {{ range $widths }}
  62. {{ $src_link := ($image.Resize (printf "%dx" .)).RelPermalink }}
  63. {{ if eq $img_src "" }}
  64. {{ $img_src = $src_link }}
  65. {{ end }}
  66. {{ $img_src_set = $img_src_set | append (printf "%s %dw" $src_link .) }}
  67. {{ end }}
  68. {{ $img_src_set = delimit $img_src_set "," }}
  69. <img src="{{ $legacy_img.RelPermalink }}" srcset="{{ $img_src_set }}" width="{{ $image.Width }}" height="{{ $image.Height }}" alt="{{ $page.Title }}">
  70. {{ else }}
  71. {{ $media_dir := $.Scratch.Get "media_dir" }}
  72. <img src="{{ printf "%s/%s" $media_dir $page.Params.hero_media | relURL }}" alt="{{ $page.Title }}">
  73. {{ end }}
  74. </div>
  75. </div>
  76. {{ end }}