widget_page.html 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. {{ partial "header.html" . }}
  2. {{ partial "navbar.html" . }}
  3. {{/* Notify JS that this is a widget page */}}
  4. <span class="js-widget-page d-none"></span>
  5. {{/* Get widget page */}}
  6. {{ $page := "" }}
  7. {{ if .IsHome }}
  8. {{ $page = "/home" }}
  9. {{ else }}
  10. {{ $page = .File.Path }}
  11. {{ end }}
  12. {{ $headless_bundle := site.GetPage $page }}
  13. {{/* Check homepage exists */}}
  14. {{ if not $headless_bundle }}
  15. {{ errorf "Homepage not found or duplicate homepages detected for a localization! Add the `home/` folder (especially `/home/index.md`) 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://sourcethemes.com/academic/docs/ and the example homepage at https://github.com/gcushen/hugo-academic/tree/master/exampleSite/content/home/index.md ." }}
  16. {{ end }}
  17. {{/* Load page sections */}}
  18. {{ range $index, $st := where ( $headless_bundle.Resources.ByType "page" ) ".Params.active" "!=" false }}
  19. {{/* Begin widget styling */}}
  20. {{ $bg := $st.Params.design.background }}
  21. {{ $style := "" }}
  22. {{ if $bg.color }}
  23. {{ $style = printf "background-color: %s;" ($bg.color | default "transparent") }}
  24. {{ end }}
  25. {{ if and $bg.gradient_start $bg.gradient_end }}
  26. {{ $style = printf "%sbackground-image: linear-gradient(%s, %s);" $style $bg.gradient_start $bg.gradient_end }}
  27. {{ end }}
  28. {{ if $bg.image }}
  29. {{ $darken := "" }}
  30. {{ if $bg.image_darken }}
  31. {{ $darken = printf "linear-gradient(rgba(0, 0, 0, %s), rgba(0, 0, 0, %s))," (string $bg.image_darken) (string $bg.image_darken) }}
  32. {{ end }}
  33. {{/* See Hugo note on linking assets in styles: https://github.com/gohugoio/hugoThemes#common-permalink-issues */}}
  34. {{ $style = printf "%sbackground-image: %s url('%s');" $style $darken (printf "img/%s" $bg.image | absURL) }}
  35. {{ end }}
  36. {{ with $st.Params.design.spacing.padding }}
  37. {{ $style_pad := printf "padding: %s;" (delimit . " ") }}
  38. {{ $style = print $style $style_pad }}
  39. {{ end }}
  40. {{ with $st.Params.advanced.css_style }}
  41. {{ $style = print $style . }}
  42. {{ end }}
  43. {{/* Fix Hugo's ContentBaseName returning wrong file base name when page section is within a bundle. */}}
  44. {{ $hash_id := replace $st.File.ContentBaseName "index" (path.Base (path.Split .Path).Dir) }}
  45. {{ $widget := or $st.Params.widget "blank" }}
  46. {{ if eq $widget "custom" }}{{ $widget = "blank" }}{{ end }}{{/* Support legacy Custom widget */}}
  47. {{ if eq $widget "projects" }}{{ $widget = "portfolio" }}{{ end }}{{/* Support legacy Projects widget */}}
  48. {{ $widget_path := printf "widgets/%s.html" $widget }}
  49. {{ $widget_args := dict "root" $ "page" $st "hash_id" $hash_id }}
  50. {{ $css_classes := $st.Params.advanced.css_class | default "" }}
  51. {{ $extra_attributes := "" }}
  52. {{ $use_container := true }}
  53. {{/* Special case: Slider widget. */}}
  54. {{ if in (slice "slider") $widget }}
  55. {{ $css_classes = print $css_classes " carousel slide" }}
  56. {{ $extra_attributes = printf "data-ride=\"carousel\" data-interval=\"%s\"" (string $st.Params.interval | default "5000") }}
  57. {{ $use_container = false }}
  58. {{ end }}
  59. <section id="{{$hash_id}}" class="home-section {{printf "wg-%s" (replace $widget "_" "-")}} {{if $bg.text_color_light}}dark{{end}} {{if $bg.image}}parallax{{end}} {{with $css_classes}}{{.}}{{end}}" {{with $style}}style="{{. | safeCSS}}"{{end}} {{print $extra_attributes | safeHTMLAttr}}>
  60. {{if $use_container}}<div class="container">{{end}}
  61. {{ partial $widget_path $widget_args }}
  62. {{if $use_container}}</div>{{end}}
  63. </section>
  64. {{ end }}
  65. {{ partial "footer_container.html" . }}
  66. {{ partial "footer.html" . }}