page_header.html 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. {{ $page := . }}
  2. {{ $featured := (.Resources.ByType "image").GetMatch "*featured*" }}
  3. {{ $anchor := $page.Params.image.focal_point | default "Smart" }}
  4. {{/* Set default titles for node pages */}}
  5. {{ $title := .Title }}
  6. {{ if and (not $title) .IsNode }}
  7. {{ if eq .Type "post" }}
  8. {{ $title = i18n "posts" }}
  9. {{ else if eq .Type "event" }}
  10. {{ $title = i18n "talks" }}
  11. {{ else if eq .Type "publication" }}
  12. {{ $title = i18n "publications" }}
  13. {{end}}
  14. {{end}}
  15. {{/* Header image */}}
  16. {{ if and .Params.header.image (not (and $featured (not .Params.image.preview_only))) }}
  17. <div class="article-header">
  18. {{- $img := "" -}}
  19. {{ $alt := (.Params.header.caption | default "") | plainify }}
  20. {{ $destination := .Params.header.image }}
  21. {{ $is_remote := strings.HasPrefix $destination "http" }}
  22. {{- if not $is_remote -}}
  23. {{- $img = (.Page.Resources.ByType "image").GetMatch $destination -}}
  24. {{- if not $img -}}
  25. {{- $img = resources.Get (path.Join "media" $destination) -}}
  26. {{- end -}}
  27. {{- end -}}
  28. {{ if $img }}
  29. <img src="{{$img.RelPermalink}}" width="{{$img.Width}}" height="{{$img.Height}}" class="article-banner" alt="{{$alt}}">
  30. {{ else }}
  31. <img src="{{ .Params.header.image }}" class="article-banner" alt="{{$alt}}">
  32. {{ end }}
  33. {{ with .Params.header.caption }}<span class="article-header-caption">{{ . | markdownify | emojify }}</span>{{ end }}
  34. </div>
  35. {{end}}
  36. {{/* Featured image layout */}}
  37. {{ if and $featured (not .Params.image.preview_only) }}
  38. {{/* Fit image within max size. */}}
  39. {{ $image := $featured }}
  40. {{/* Determine image placement. */}}
  41. {{ $placement := .Params.image.placement | default 1 }}{{/* Default to full column width. */}}
  42. {{ $image_container := "" }}
  43. {{ if eq $placement 2}}
  44. {{ $image_container = "container" }}
  45. {{ if gt $featured.Width 1200 }}
  46. {{ $image = $featured.Resize "1200x" }}
  47. {{ end }}
  48. {{else if eq $placement 3}}
  49. {{ $image_container = "container-fluid" }}
  50. {{ $image := $featured.Fit "2560x2560" }}
  51. {{else}}
  52. {{ $image_container = "article-container" }}
  53. {{ if gt $featured.Width 720 }}
  54. {{ $image = $featured.Resize "720x" }}
  55. {{ end }}
  56. {{end}}
  57. <div class="article-container pt-3">
  58. <h1>{{ $title }}</h1>
  59. {{ with $page.Params.subtitle }}
  60. <p class="page-subtitle">{{ . | markdownify | emojify }}</p>
  61. {{end}}
  62. {{ partial "page_metadata" (dict "page" $page "is_list" 0 "share" true) }}
  63. {{ partial "page_links_div.html" $page }}
  64. </div>
  65. {{/* Featured image */}}
  66. <div class="article-header {{$image_container}} featured-image-wrapper mt-4 mb-4" style="max-width: {{$image.Width}}px; max-height: {{$image.Height}}px;">
  67. <div style="position: relative">
  68. <img src="{{ $image.RelPermalink }}" width="{{ $image.Width }}" height="{{ $image.Height }}" alt="{{ with $.Params.image.alt_text }}{{.}}{{ end }}" class="featured-image">
  69. {{ with $.Params.image.caption }}<span class="article-header-caption">{{ . | markdownify | emojify }}</span>{{ end }}
  70. </div>
  71. </div>
  72. {{else}}
  73. {{/* Case when page has no image */}}
  74. {{/* Wider container for nodes */}}
  75. {{ $ctnr := "article-container" }}
  76. {{ if $page.IsNode }}
  77. {{ $ctnr = "universal-wrapper" }}
  78. {{end}}
  79. <div class="{{$ctnr}} pt-3">
  80. <h1>{{ $title }}</h1>
  81. {{ with $page.Params.subtitle }}
  82. <p class="page-subtitle">{{ . | markdownify | emojify }}</p>
  83. {{end}}
  84. {{ if not .IsNode }}
  85. {{ partial "page_metadata" (dict "page" $page "is_list" 0 "share" true) }}
  86. {{ partial "page_links_div.html" $page }}
  87. {{end}}
  88. </div>
  89. {{end}}