widget_page.html 6.6 KB

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