widget_page.html 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. {{ errorf "Homepage not found at %s!" $page }}
  12. {{ errorf "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 ." }}
  13. {{ end }}
  14. {{ else }}
  15. {{ $page = .File.Path }}
  16. {{ $headless_bundle = site.GetPage $page }}
  17. {{/* Check widget page exists. */}}
  18. {{ if not $headless_bundle }}
  19. {{ errorf "Widget Page not found at %s!" $page }}
  20. {{ errorf "View the Widget Page documentation at https://wowchemy.com/docs/managing-content/#create-a-widget-page ." }}
  21. {{ errorf "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-modules/issues/1595#issuecomment-605514973 ." }}
  22. {{ end }}
  23. {{ end }}
  24. {{/* Load page sections */}}
  25. {{ range $index, $st := where ( $headless_bundle.Resources.ByType "page" ) ".Params.active" "!=" false }}
  26. {{/* Begin widget styling */}}
  27. {{ $bg := $st.Params.design.background }}
  28. {{ $style := "" }}
  29. {{ if $bg.color }}
  30. {{ $style = printf "background-color: %s;" ($bg.color | default "transparent") }}
  31. {{ end }}
  32. {{ if and $bg.gradient_start $bg.gradient_end }}
  33. {{ $style = printf "%sbackground-image: linear-gradient(%s, %s);" $style $bg.gradient_start $bg.gradient_end }}
  34. {{ end }}
  35. {{ if $bg.image }}
  36. {{ $darken := "" }}
  37. {{ if $bg.image_darken }}
  38. {{ $darken = printf "linear-gradient(rgba(0, 0, 0, %s), rgba(0, 0, 0, %s))," (string $bg.image_darken) (string $bg.image_darken) }}
  39. {{ end }}
  40. {{/* See Hugo note on linking assets in styles: https://github.com/gohugoio/hugoThemes#common-permalink-issues */}}
  41. {{ $media_dir := $.Scratch.Get "media_dir" }}
  42. {{ $style = printf "%sbackground-image: %s url('%s');" $style $darken (printf "%s/%s" $media_dir $bg.image | absURL) }}
  43. {{ with $bg.image_size }}
  44. {{/* Allow sizes: actual, cover, and contain. */}}
  45. {{ $style = printf "%sbackground-size: %s;" $style (replace . "actual" "auto") }}
  46. {{ end }}
  47. {{ with $bg.image_position }}
  48. {{/* Allow valid CSS positions including left, center, and right. */}}
  49. {{ $style = printf "%sbackground-position: %s;" $style . }}
  50. {{ end }}
  51. {{ end }}
  52. {{ with $st.Params.design.spacing.padding }}
  53. {{ $style_pad := printf "padding: %s;" (delimit . " ") }}
  54. {{ $style = print $style $style_pad }}
  55. {{ end }}
  56. {{/* Support for clip path (design.clip_path) */}}
  57. {{ with $st.Params.design.clip_path }}
  58. {{ $style_clip_path := printf "clip-path: %s;" . }}
  59. {{ $style = print $style $style_clip_path }}
  60. {{ end }}
  61. {{ with $st.Params.advanced.css_style }}
  62. {{ $style = print $style . }}
  63. {{ end }}
  64. {{/* Fix Hugo's ContentBaseName returning wrong file base name when page section is within a bundle. */}}
  65. {{ $hash_id := replace $st.File.ContentBaseName "index" (path.Base (path.Split .Path).Dir) }}
  66. {{ $widget := or $st.Params.widget "blank" }}
  67. {{ if eq $widget "custom" }}{{ $widget = "blank" }}{{ end }}{{/* Support legacy Custom widget */}}
  68. {{ if eq $widget "projects" }}{{ $widget = "portfolio" }}{{ end }}{{/* Support legacy Projects widget */}}
  69. {{ $widget_path := printf "widgets/%s.html" $widget }}
  70. {{ $widget_args := dict "root" $ "page" $st "hash_id" $hash_id }}
  71. {{ $css_classes := $st.Params.advanced.css_class | default "" }}
  72. {{ $extra_attributes := "" }}
  73. {{ $use_container := true }}
  74. {{/* Special case: Slider widget. */}}
  75. {{ if in (slice "slider") $widget }}
  76. {{ $css_classes = print $css_classes " carousel slide" }}
  77. {{ $extra_attributes = printf "data-ride=\"carousel\" data-interval=\"%s\"" (string $st.Params.interval | default "5000") }}
  78. {{ $use_container = false }}
  79. {{ end }}
  80. {{ $widget_class := printf "wg-%s" (replace (replace $widget "." "-") "_" "-") }}
  81. {{ $widget_config_file := printf "widgets/%s-config.html" $widget }}
  82. {{ if templates.Exists $widget_config_file }}
  83. {{ $cfg := partial $widget_config_file $widget_args }}
  84. {{ $use_container = $cfg.use_container }}
  85. {{end}}
  86. <section id="{{$hash_id}}" class="home-section {{$widget_class}} {{if $bg.text_color_light}}dark{{end}} {{if $bg.image}} bg-image{{if ($bg.image_parallax | default true) }} parallax{{end}}{{end}} {{with $css_classes}}{{.}}{{end}}" {{with $style}}style="{{. | safeCSS}}"{{end}} {{print $extra_attributes | safeHTMLAttr}}>
  87. {{if $use_container}}<div class="container">{{end}}
  88. {{ partial $widget_path $widget_args }}
  89. {{if $use_container}}</div>{{end}}
  90. </section>
  91. {{ end }}