<!-- Prematurely connect to the servers to save some milliseconds -->
<!-- <link rel="preload"> is only in recent browser versions, so we keep "dns-prefetch" and "preconnect" -->
<!-- <link rel="prefetch" loads content the user may request *after* the page loads -->

{{- with $.Site.Params.thumbnail -}}
<meta name="thumbnail" content="{{ partial "make_link" (dict "URL" . "Root" $) }}" />
{{- end -}}

{{ partial "fontawesome/head.html" . }}

{{ partial "matomo/head.html" . }}

<!--{{ partial "styles" (dict "Asset" "css/foundation.css" "Root" $) }}-->

<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/foundation.min.js"></script>
<script type="text/javascript" src="/js/lunr.min.js"></script>
<link rel="stylesheet" type="text/css" href="/css/foundation.css">


{{- $assets := slice -}}

{{- .Scratch.Set "sitevar" $.Site -}}
{{- partial "css/color/parse_color" .Scratch -}}
{{- .Scratch.Set "label" "alt_bg" -}}
{{- partial "css/color/detect_light_or_dark" .Scratch -}}

{{- if ($.Scratch.Get "alt_bg_is_dark") -}}
    {{- if or $.Site.Params.http2 (getenv "HUGO_HTTP2") -}}
        {{- partial "styles" (dict "Asset" "css/dark.css" "Root" $) -}}
    {{- else -}}
        {{- .Scratch.Set "code_css" "css/dark.css" -}}
    {{- end -}}
{{- else -}}
    {{- if or $.Site.Params.http2 (getenv "HUGO_HTTP2") -}}
        {{- partial "styles" (dict "Asset" "css/light.css" "Root" $) -}}
    {{- else -}}
        {{- .Scratch.Set "code_css" "css/light.css" -}}
    {{- end -}}
{{- end -}}

{{ partial "styles" (dict "Src" "/styles.css" "Root" $) }}

{{- if or $.Site.Params.http2 (getenv "HUGO_HTTP2") -}}
    {{ $files := slice "reset" "fonts" "classes" "pagination" "page" "widgets" }}
    {{ range $f := $files }}
        {{- partial "styles" (dict "Asset" (printf "css/%s.css" $f) "Root" $ ) -}}
    {{- end -}}
{{ end }}

{{- if not (or $.Site.Params.http2 (getenv "HUGO_HTTP2")) -}}
    {{- $reset := resources.Get "css/reset.css" -}}
    {{- $codecss := resources.Get (.Scratch.Get "code_css") -}}
    {{- $fonts := resources.Get "css/fonts.css" -}}
    {{- $classes := resources.Get "css/classes.css" -}}
    {{- $pagination := resources.Get "css/pagination.css" -}}
    {{- $page := resources.Get "css/page.css" -}}
    {{- $widgets := resources.Get "css/widgets.css" -}}
    {{- $css := slice $reset $codecss $fonts $classes $pagination $page $widgets | resources.Concat "css/bundle.css" | fingerprint -}}
    {{- partial "styles" (dict "Src" $css.RelPermalink "Integrity" $css.Data.Integrity "Root" $ ) -}}
{{- end -}}

{{ if eq .Kind "page" }}
    {{ partial "styles" (dict "Asset" "css/single.css" "Root" $) }}
{{ else }}
    {{ partial "styles" (dict "Asset" "css/list.css" "Root" $) }}
{{ end }}

{{ if .Content -}}
    {{ $figures := findRE "<figure" .Content -}}
    {{ $forms := findRE "<input" .Content -}}
    {{ $tables := findRE "<table" .Content -}}
    
    {{ if gt (len $figures) 0 }}
        {{ partial "styles" (dict "Asset" "css/figure.css" "Root" $) }}
    {{ end }}
    
    {{ if or (gt (len $forms) 0) $.Site.Params.comments.provider }}
        {{ partial "styles" (dict "Asset" "css/forms.css" "Root" $) }}
    {{ end }}
    
    {{ if gt (len $tables) 0 }}
        {{ partial "styles" (dict "Asset" "css/table.css" "Root" $) }}
    {{ end }}
{{ end -}}

{{ if $.Site.Params.iubenda.id }}
    {{ partial "styles" (dict "Asset" "css/iubenda.css" "Root" $) }}
{{ end }}

{{- $url := "" -}}
{{- $integrity := "" -}}
{{- if $.Site.Params.no_minify -}}
    {{- $res := resources.Get "css/print.css" | fingerprint -}}
    {{- $url = $res.RelPermalink -}}
    {{- $integrity = $res.Data.Integrity -}}
{{- else -}}
    {{- $res := resources.Get "css/print.css" | minify | fingerprint -}}
    {{- $url = $res.RelPermalink -}}
    {{- $integrity = $res.Data.Integrity -}}
{{- end -}}
<link rel="preload" media="print" type="text/css" href="{{ partial "make_link" (dict "URL" $url "Root" $) }}" integrity="{{ $integrity }}" as="style">

{{- partial "shortcodes/partial.html" (dict "Prop" "head" "Root" $) -}}

{{- partial "sidebar/partial.html" (dict "Prop" "head" "Root" $) -}}

{{- partial "comments/partial.html" (dict "Prop" "head" "Root" $) -}}

{{- partial "plugins/partial.html" (dict "Prop" "head" "Root" $) -}}

{{ partial "matomo/head2.html" . }}

{{- partial "favicons.html" . -}}