{{ partial "header.html" . }}
{{ partial "navbar.html" . }}

<!-- Flag for jQuery -->
<span id="homepage" class="d-none"></span>

{{/* Get widget page */}}
{{ $page := "" }}
{{ if .IsHome }}
  {{ $page = "/home" }}
{{ else }}
  {{ $page = .File.Path }}
{{ end }}
{{ $headless_bundle := site.GetPage $page }}
{{/* Check homepage exists */}}
{{ if not $headless_bundle }}
  {{ 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 ." }}
{{ end }}

{{/* Load page sections */}}
{{ range $index, $st := where ( $headless_bundle.Resources.ByType "page" ) ".Params.active" "!=" false }}
  {{/* Begin widget styling */}}
  {{ $bg := $st.Params.design.background }}
  {{ $style := "" }}

  {{ if $bg.color }}
    {{ $style = printf "background-color: %s;" ($bg.color | default "transparent") }}
  {{ end }}

  {{ if and $bg.gradient_start $bg.gradient_end }}
    {{ $style = printf "%sbackground-image: linear-gradient(%s, %s);" $style $bg.gradient_start $bg.gradient_end }}
  {{ end }}

  {{ if $bg.image }}
    {{ $darken := "" }}
    {{ if $bg.image_darken }}
      {{ $darken = printf "linear-gradient(rgba(0, 0, 0, %s), rgba(0, 0, 0, %s))," (string $bg.image_darken) (string $bg.image_darken) }}
    {{ end }}
    {{/* See Hugo note on linking assets in styles: https://github.com/gohugoio/hugoThemes#common-permalink-issues */}}
    {{ $style = printf "%sbackground-image: %s url('%s');" $style $darken (printf "img/%s" $bg.image | absURL) }}
  {{ end }}

  {{ with $st.Params.design.spacing.padding }}
    {{ $style_pad := printf "padding: %s;" (delimit . " ") }}
    {{ $style = print $style $style_pad }}
  {{ end }}

  {{ with $st.Params.advanced.css_style }}
    {{ $style = print $style . }}
  {{ end }}

  {{ $params := dict "root" $ "page" $st }}
  {{ $hash_id := replace $st.File.ContentBaseName "index" (path.Base (path.Split .Path).Dir) }}

  {{ $widget := or $st.Params.widget "blank" }}
  {{ if eq $widget "custom" }}{{ $widget = "blank" }}{{ end }}{{/* Support legacy Custom widget */}}
  {{ if eq $widget "projects" }}{{ $widget = "portfolio" }}{{ end }}{{/* Support legacy Projects widget */}}

  {{ $widget_path := printf "widgets/%s.html" $widget }}
  {{ if in (slice "slider") $widget }}
    {{ partial $widget_path $params }}
  {{ else }}
  <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 $st.Params.advanced.css_class }}{{ . }}{{ end }}" {{with $style}}style="{{. | safeCSS}}"{{end}}>
    <div class="container">
      {{ partial $widget_path $params }}
    </div>
  </section>
  {{ end }}
{{ end }}

{{ partial "footer_container.html" . }}
{{ partial "footer.html" . }}
