widget_page.html 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. {{/* Notify JS that this is a widget page */}}
  2. <span class="js-widget-page d-none"></span>
  3. {{/* Get widget page */}}
  4. {{ $page := "" }}
  5. {{ $headless_bundle := "" }}
  6. {{ if .IsHome }}
  7. {{ $page = "/home/index.md" }}
  8. {{ $headless_bundle = site.GetPage $page }}
  9. {{/* Check homepage exists */}}
  10. {{ if not $headless_bundle }}
  11. {{ warnf "Hugo cannot find a Widget Page at %s!" $page }}
  12. {{ warnf "If the page exists, Hugo Server may need restarting due to file changes." }}
  13. {{ warnf "Add the `/home/index.md` homepage file to each language's content folder. For example, your site should have a `content/home/` folder containing `index.md` and your homepage sections, or for multi-language sites, `content/en/home/` and `content/zh/home/` etc. Refer to the 'Build Your Homepage' and 'Language' documentation at https://wowchemy.com/docs/ and the example homepage at https://github.com/wowchemy/starter-academic/tree/master/exampleSite/content/home/index.md ." }}
  14. {{ end }}
  15. {{ else }}
  16. {{ $page = .File.Path }}
  17. {{ $headless_bundle = site.GetPage $page }}
  18. {{/* Check widget page exists. */}}
  19. {{ if not $headless_bundle }}
  20. {{ warnf "Hugo cannot find a Widget Page at %s!" $page }}
  21. {{ warnf "If the page exists, Hugo Server may need restarting due to file changes." }}
  22. {{ warnf "View the Widget Page documentation at https://wowchemy.com/docs/managing-content/#create-a-widget-page ." }}
  23. {{ warnf "If the Hugo version is between 0.65 and 0.68, it may be a confirmed Hugo bug that is expected to be fixed in Hugo v0.69: https://github.com/wowchemy/wowchemy-hugo-themes/issues/1595#issuecomment-605514973 ." }}
  24. {{ end }}
  25. {{ end }}
  26. {{/* Load page sections */}}
  27. {{ range $index, $st := where ( $headless_bundle.Resources.ByType "page" ) ".Params.active" "!=" false }}
  28. {{/* Begin widget styling */}}
  29. {{ $bg := $st.Params.design.background }}
  30. {{ $style := "" }}
  31. {{ $style_bg := "" }}
  32. {{ if $bg.color }}
  33. {{ $style_bg = printf "background-color: %s;" ($bg.color | default "transparent") }}
  34. {{ end }}
  35. {{ if and $bg.gradient_start $bg.gradient_end }}
  36. {{ $angle := string $bg.gradient_angle | default "90" }}
  37. {{ $style_bg = printf "%sbackground-image: linear-gradient(%sdeg, %s, %s);" $style_bg $angle $bg.gradient_start $bg.gradient_end }}
  38. {{ end }}
  39. {{ $bg_video := "" }}
  40. {{ if $bg.video.path }}
  41. {{ $bg_video = resources.Get (printf "media/%s" $bg.video.path) }}
  42. {{ end }}
  43. {{ $bg_video_class := "" }}
  44. {{ if $bg.video.flip }}
  45. {{ $bg_video_class = "flip" }}
  46. {{ end }}
  47. {{ if $bg.image }}
  48. {{/* See Hugo note on linking assets in styles: https://github.com/gohugoio/hugoThemes#common-permalink-issues */}}
  49. {{ $bg_img := resources.Get (printf "media/%s" $bg.image) }}
  50. {{ if $bg_img }}
  51. {{ $bg_img = $bg_img.Fit "1920x1920 webp" }}
  52. {{ $style_bg = printf "%sbackground-image: url('%s');" $style_bg $bg_img.Permalink }}
  53. {{ else }}
  54. {{ errorf "Couldn't find `%s` in the `assets/media/` folder - please add it." $bg.image }}
  55. {{ end }}
  56. {{ with $bg.image_size }}
  57. {{/* Allow sizes: actual, cover, and contain. */}}
  58. {{ $style_bg = printf "%sbackground-size: %s;" $style_bg (replace . "actual" "auto") }}
  59. {{ end }}
  60. {{ with $bg.image_position }}
  61. {{/* Allow valid CSS positions including left, center, and right. */}}
  62. {{ $style_bg = printf "%sbackground-position: %s;" $style_bg . }}
  63. {{ end }}
  64. {{ end }}
  65. {{ if $bg.image_darken }}
  66. {{ $style_bg = printf "%sfilter: brightness(%s);" $style_bg (string $bg.image_darken) }}
  67. {{ end }}
  68. {{ with $st.Params.design.spacing.padding }}
  69. {{ $style_pad := printf "padding: %s;" (delimit . " ") }}
  70. {{ $style = print $style $style_pad }}
  71. {{ end }}
  72. {{/* Support for clip path (design.clip_path) */}}
  73. {{ with $st.Params.design.clip_path }}
  74. {{ $style_clip_path := printf "clip-path: %s;" . }}
  75. {{ $style = print $style $style_clip_path }}
  76. {{ end }}
  77. {{ with ($st.Params.design.css_style | default $st.Params.advanced.css_style) }}
  78. {{ $style = print $style . }}
  79. {{ end }}
  80. {{/* Fix Hugo's ContentBaseName returning wrong file base name when page section is within a bundle. */}}
  81. {{ $hash_id := replace $st.File.ContentBaseName "index" (path.Base (path.Split .Path).Dir) }}
  82. {{ $widget := or $st.Params.widget "blank" }}
  83. {{ if eq $widget "custom" }}{{ $widget = "blank" }}{{ end }}{{/* Support legacy Custom widget */}}
  84. {{ if eq $widget "projects" }}{{ $widget = "portfolio" }}{{ end }}{{/* Support legacy Projects widget */}}
  85. {{ $widget_path := printf "widgets/%s.html" $widget }}
  86. {{ $widget_args := dict "root" $ "page" $st "hash_id" $hash_id }}
  87. {{ $css_classes := $st.Params.design.css_class | default $st.Params.advanced.css_class | default "" }}
  88. {{ $extra_attributes := "" }}
  89. {{ $use_container := true }}
  90. {{/* Special case: Slider widget. */}}
  91. {{ if in (slice "slider") $widget }}
  92. {{ $css_classes = print $css_classes " carousel slide" }}
  93. {{ $extra_attributes = printf "data-ride=\"carousel\" data-interval=\"%s\"" (cond ($st.Params.design.loop | default true) (string $st.Params.design.interval | default "3000") "false") }}
  94. {{ $use_container = false }}
  95. {{ end }}
  96. {{ $widget_class := printf "wg-%s" (replace (replace $widget "." "-") "_" "-") }}
  97. {{ $widget_config_file := printf "widgets/%s-config.html" $widget }}
  98. {{ if templates.Exists $widget_config_file }}
  99. {{ $cfg := partial $widget_config_file $widget_args }}
  100. {{ $use_container = $cfg.use_container }}
  101. {{end}}
  102. {{ $columns := $st.Params.design.columns | default "2" }}
  103. {{ $use_cols := in (slice "pages" "featured" "experience" "accomplishments" "contact" "blank" "tag_cloud" "portfolio") $widget }}
  104. {{/* Dedicated child div for bg prevents parallax 100% height issue within new CSS grid page wrapper. */}}
  105. <section id="{{$hash_id}}" class="home-section {{$widget_class}} {{if $bg.text_color_light}}dark{{else if (eq $bg.text_color_light false)}}light{{end}} {{with $css_classes}}{{.}}{{end}}" {{with $style}}style="{{. | safeCSS}}"{{end}} {{print $extra_attributes | safeHTMLAttr}}>
  106. <div class="home-section-bg {{if $bg.image}} bg-image{{if ($bg.image_parallax | default true) }} parallax{{end}}{{end}}" {{with $style_bg}}style="{{. | safeCSS}}"{{end}}>
  107. {{with $bg_video}}<video class="bg-video {{$bg_video_class}}" playsinline="" preload="auto" loop="" muted autoplay="" tabindex="-1" width="100%" height="100%" src="{{.RelPermalink}}" style="width: 100%; height: 100%; object-fit: cover; object-position: center center; opacity: 1;"></video>{{end}}
  108. </div>
  109. {{if $use_container}}<div class="container">{{end}}
  110. {{if $use_cols}}
  111. <div class="row {{if not $st.Title | or (eq $columns "1") }}justify-content-center{{end}}">
  112. {{ if $st.Title }}
  113. {{ if eq $columns "1" }}
  114. <div class="section-heading col-12 mb-3 text-center">
  115. {{ with $st.Title }}<h1 class="mb-0">{{ . | markdownify | emojify }}</h1>{{ end }}
  116. {{ with $st.Params.subtitle }}<p class="mt-1">{{ . | markdownify | emojify }}</p>{{ end }}
  117. </div>
  118. {{else}}
  119. <div class="section-heading col-12 col-lg-4 mb-3 mb-lg-0 d-flex flex-column align-items-center align-items-lg-start">
  120. {{ with $st.Title }}<h1 class="mb-0">{{ . | markdownify | emojify }}</h1>{{ end }}
  121. {{ with $st.Params.subtitle }}<p class="mt-1">{{ . | markdownify | emojify }}</p>{{ end }}
  122. </div>
  123. {{end}}
  124. {{end}}
  125. {{end}}
  126. {{ partial $widget_path $widget_args }}
  127. {{if $use_cols}}
  128. </div>
  129. {{end}}
  130. {{if $use_container}}</div>{{end}}
  131. </section>
  132. {{ end }}