widget_page.html 6.3 KB

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