{{- $s := .Site.Params }}
{{- $p := .Params }}
<!DOCTYPE html>
<html lang="{{ .Lang }}" data-figures="{{ $p.figurePositionShow }}"{{ if .IsPage }} class="page"{{ end }}{{ with $s.enforceLightMode }} data-mode="lit"{{ end }}{{ with $s.enforceDarkMode }} data-mode="dim"{{ end }}>
  <head>
    {{- partial "head" . }}
    <!-- styles definition-->
    {{- $options := (dict "targetPath" "css/styles.css" "outputStyle" "compressed" "enableSourceMap" "true") -}}
    {{ $mainSassFile :=  "sass/main.sass" }}
    {{- $styles := resources.Get $mainSassFile | resources.ExecuteAsTemplate $mainSassFile . | resources.ToCSS $options }}
    {{- if (eq (getenv "HUGO_ENV") "production") -}}
      {{- $styles = $styles | minify | fingerprint "sha512" -}}
    {{- end -}}

    <!-- scripts definition -->
    {{- $highlightPath := "js/highlight.js" }}
    {{- $highlight := resources.Get $highlightPath | resources.ExecuteAsTemplate $highlightPath . }}

    {{- $functionsScriptPath := "js/functions.js" }}
    {{- $functions := resources.Get $functionsScriptPath | resources.ExecuteAsTemplate $functionsScriptPath . }}

    {{- $codeScriptPath := "js/code.js" }}
    {{- $code := resources.Get $codeScriptPath | resources.ExecuteAsTemplate $codeScriptPath . }}

    {{- $customScriptPath := "js/custom.js" }}
    {{ if (fileExists "../../assets/js/custom.js") }}
      {{ $customScriptPath := "../../assets/js/custom.js" }}
    {{ end }}
    {{- $custom := resources.Get $customScriptPath | resources.ExecuteAsTemplate $customScriptPath . }}

    {{- $mainScriptPath := "js/index.js" }}
    {{- $main := resources.Get $mainScriptPath | resources.ExecuteAsTemplate $mainScriptPath . }}

    {{- $bundle := slice $highlight $functions $code $main $custom | resources.Concat "js/bundle.js" | resources.Minify | resources.Fingerprint "sha512" -}}

    <!-- preload assets declaration -->
    <link rel="preload" href="{{ $styles.Permalink }}" integrity = "{{ $styles.Data.Integrity }}" as="style" crossorigin="anonymous">
    <link rel="preload" href="{{ $bundle.Permalink }}" as="script" integrity=
    "{{ $bundle.Data.Integrity }}" crossorigin="anonymous">

    <!-- styles file -->
    <link rel="stylesheet" type="text/css" href="{{ $styles.Permalink }}" integrity="{{ $styles.Data.Integrity }}" crossorigin="anonymous">
    {{- with $s.customCSS }}
    {{- range . -}}
	  <link rel="stylesheet" href="{{ relURL . }}">
    {{- end }}
    {{- end }}
    {{ partial "hooks/head-end.html" . }}
  </head>
  {{- $maxCodeLines := 100 }}
  {{- with $s.codeMaxLines }}
    {{- $maxCodeLines = . }}
  {{- end }}
  {{- with $p.codeMaxLines }}
    {{- $maxCodeLines = . }}
  {{- end }}
  {{- $codeLineNumbers := false }}
  {{ with $s.codeLineNumbers }}
    {{- $codeLineNumbers = . }}
  {{ end }}
  {{ with $p.codeLineNumbers }}
    {{- $codeLineNumbers = . }}
    {{ else }}
    {{ if eq $p.codeLineNumbers false }}
      {{- $codeLineNumbers = false }}
    {{ end }}
  {{ end }}
  <body data-code="{{ $maxCodeLines }}" data-lines="{{ $codeLineNumbers }}" id="documentTop">
    {{- partial "header" . }}
    <main>
      {{- block "main" . }}{{ end }}
    </main>
    {{- partial "icons" }}
    {{- partial "footer" . }}
    <script type="text/javascript" src="{{ $bundle.Permalink }}" integrity="{{ $bundle.Data.Integrity }}" crossorigin="anonymous"></script>
    {{- with $s.customJS }}
    {{- range . -}}
    <script type="text/javascript" src="{{ relURL . }}" ></script>
    {{- end }}
    {{- end }}
    {{ partial "hooks/body-end.html" . }}
  </body>
</html>
