widget_page.html 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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-modules/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. {{ if $bg.image }}
  40. {{/* See Hugo note on linking assets in styles: https://github.com/gohugoio/hugoThemes#common-permalink-issues */}}
  41. {{ $bg_img := resources.Get (printf "media/%s" $bg.image) }}
  42. {{ if $bg_img }}
  43. {{ $style_bg = printf "%sbackground-image: url('%s');" $style_bg $bg_img.Permalink }}
  44. {{ else }}
  45. {{ errorf "Couldn't find `%s` in the `assets/media/` folder - please add it." $bg.image }}
  46. {{ end }}
  47. {{ with $bg.image_size }}
  48. {{/* Allow sizes: actual, cover, and contain. */}}
  49. {{ $style_bg = printf "%sbackground-size: %s;" $style_bg (replace . "actual" "auto") }}
  50. {{ end }}
  51. {{ with $bg.image_position }}
  52. {{/* Allow valid CSS positions including left, center, and right. */}}
  53. {{ $style_bg = printf "%sbackground-position: %s;" $style_bg . }}
  54. {{ end }}
  55. {{ end }}
  56. {{ if $bg.image_darken }}
  57. {{ $style_bg = printf "%sfilter: brightness(%s);" $style_bg (string $bg.image_darken) }}
  58. {{ end }}
  59. {{ with $st.Params.design.spacing.padding }}
  60. {{ $style_pad := printf "padding: %s;" (delimit . " ") }}
  61. {{ $style = print $style $style_pad }}
  62. {{ end }}
  63. {{/* Support for clip path (design.clip_path) */}}
  64. {{ with $st.Params.design.clip_path }}
  65. {{ $style_clip_path := printf "clip-path: %s;" . }}
  66. {{ $style = print $style $style_clip_path }}
  67. {{ end }}
  68. {{ with $st.Params.advanced.css_style }}
  69. {{ $style = print $style . }}
  70. {{ end }}
  71. {{/* Fix Hugo's ContentBaseName returning wrong file base name when page section is within a bundle. */}}
  72. {{ $hash_id := replace $st.File.ContentBaseName "index" (path.Base (path.Split .Path).Dir) }}
  73. {{ $widget := or $st.Params.widget "blank" }}
  74. {{ if eq $widget "custom" }}{{ $widget = "blank" }}{{ end }}{{/* Support legacy Custom widget */}}
  75. {{ if eq $widget "projects" }}{{ $widget = "portfolio" }}{{ end }}{{/* Support legacy Projects widget */}}
  76. {{ $widget_path := printf "widgets/%s.html" $widget }}
  77. {{ $widget_args := dict "root" $ "page" $st "hash_id" $hash_id }}
  78. {{ $css_classes := $st.Params.advanced.css_class | default "" }}
  79. {{ $extra_attributes := "" }}
  80. {{ $use_container := true }}
  81. {{/* Special case: Slider widget. */}}
  82. {{ if in (slice "slider") $widget }}
  83. {{ $css_classes = print $css_classes " carousel slide" }}
  84. {{ $extra_attributes = printf "data-ride=\"carousel\" data-interval=\"%s\"" (string $st.Params.interval | default "5000") }}
  85. {{ $use_container = false }}
  86. {{ end }}
  87. {{ $widget_class := printf "wg-%s" (replace (replace $widget "." "-") "_" "-") }}
  88. {{ $widget_config_file := printf "widgets/%s-config.html" $widget }}
  89. {{ if templates.Exists $widget_config_file }}
  90. {{ $cfg := partial $widget_config_file $widget_args }}
  91. {{ $use_container = $cfg.use_container }}
  92. {{end}}
  93. {{ $columns := $st.Params.design.columns | default "2" }}
  94. {{ $use_cols := in (slice "pages" "featured" "experience" "accomplishments" "contact" "blank" "tag_cloud" "portfolio") $widget }}
  95. {{/* Dedicated child div for bg prevents parallax 100% height issue within new CSS grid page wrapper. */}}
  96. <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}}>
  97. <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}}></div>
  98. {{if $use_container}}<div class="container">{{end}}
  99. {{if $use_cols}}
  100. <div class="row {{if not $st.Title | or (eq $columns "1") }}justify-content-center{{end}}">
  101. {{ if $st.Title }}
  102. {{ if eq $columns "1" }}
  103. <div class="section-heading col-12 mb-3 text-center">
  104. {{ with $st.Title }}<h1 class="mb-0">{{ . | markdownify | emojify }}</h1>{{ end }}
  105. {{ with $st.Params.subtitle }}<p class="mt-1">{{ . | markdownify | emojify }}</p>{{ end }}
  106. </div>
  107. {{else}}
  108. <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">
  109. {{ with $st.Title }}<h1 class="mb-0">{{ . | markdownify | emojify }}</h1>{{ end }}
  110. {{ with $st.Params.subtitle }}<p class="mt-1">{{ . | markdownify | emojify }}</p>{{ end }}
  111. </div>
  112. {{end}}
  113. {{end}}
  114. {{end}}
  115. {{ partial $widget_path $widget_args }}
  116. {{if $use_cols}}
  117. </div>
  118. {{end}}
  119. {{if $use_container}}</div>{{end}}
  120. </section>
  121. {{ end }}