{{- $res := slice -}}
{{- $syntax := resources.Get "css/syntax.css" -}}
{{$main := $syntax}}
{{if $.Param "scss" }}
  {{- $sass := resources.Get "scss/main.scss" -}}
  {{- $cssOpts := cond (hugo.IsServer) (dict "enableSourceMap" true ) (dict "outputStyle" "compressed") -}}
    {{- $main = $sass | resources.ExecuteAsTemplate "main.scss" . | toCSS $cssOpts -}}
{{- else -}}
    {{ $main = resources.Get "compiled/main.css" | resources.ExecuteAsTemplate "main.css" .}}
{{- end -}}
    {{- $cssFiles := slice $main $syntax | resources.Concat "css/index.css" -}}
    {{- $css := $cssFiles | resources.Minify | resources.Fingerprint "sha512" }}
<link rel="stylesheet" href="{{ $css.RelPermalink }}" media="none" onload="if(media!='all')media='all'">
    {{- $res = $res | append $css.RelPermalink }}
<noscript>
  <link rel="stylesheet" href="{{ $css.RelPermalink }}" media="screen">
</noscript>
<style>
  html {
    opacity: 0;
  }
</style>
  {{- range .Site.Params.custom_css -}}
    {{- $res = $res | append . }}
<link rel="stylesheet" href="{{ . }}">
  {{- end -}}

{{- $main := resources.Get "js/main.js" | resources.ExecuteAsTemplate "js/main.js" . -}}
{{- if hugo.IsServer }}
<script type="text/javascript" src="{{ $main.RelPermalink }}" defer></script>
{{- $res = $res | append $main.RelPermalink -}}
{{- else -}}
{{- $js := slice $main | resources.Concat "index.js" | resources.Minify }}
<script type="text/javascript" src="{{ $js.RelPermalink }}" defer></script>
{{- $res = $res | append $js.RelPermalink -}}
{{- end -}}

{{- $sw := resources.Get "js/sw.js" -}}
{{- $sw = $sw | resources.ExecuteAsTemplate "sw.js" (dict "page" . "res" $res) | resources.Minify -}}
<!-- {{- $sw.RelPermalink -}} -->
<script>
  if (window.localStorage.color) {
    document.documentElement.style.setProperty("--theme-color", window.localStorage.color);
  }
  if(window.localStorage.dark === "true") {
    document.documentElement.classList.add("dark");
  }
  {{- if (.Site.Params.checksDarkMode) -}}
  if (window.matchMedia('(prefers-color-scheme: dark)').matches && window.localStorage.dark !== "false") {
    document.documentElement.classList.add("dark");
  }
  {{- end -}}
</script>
