{{ $params := . }}

{{ $context := $params.context }}
{{ $enablesourcemap := not hugo.IsProduction }}
{{ $href := $params.href }}
{{ $integrity := $params.integrity }}
{{ $origin := $params.crossorigin | default "anonymous" }}
{{ $outputstyle := cond hugo.IsProduction "compressed" "" }}
{{ $page := $params.page }}
{{ $paths := $params.includepaths }}
{{ $policy := $params.referrerpolicy | default "no-referrer" }}
{{ $resource := partial "paige/func-resource.html" (dict "page" $page "url" $href) }}
{{ $sass := $params.sass }}
{{ $template := $params.template }}

{{ if not $href }}
    {{ errorf "layouts/partials/paige/tag-link.html: no href" }}
{{ end }}

{{ if $resource  }}
    {{ if $template }}
        {{ $split := path.Split $href }}
        {{ $join := path.Join $split.Dir (print (printf "%#v" $context | sha1) "-" $split.File) }}

        {{ $resource = resources.ExecuteAsTemplate $join $context $resource }}
    {{ end }}

    {{ if $sass }}
        {{/* TODO: Remove the silenceDeprecations option when Bootstrap is updated beyond v5.3.3. */}}

        {{ $resource = $resource | toCSS (dict "enableSourceMap" $enablesourcemap "includePaths" $paths "outputStyle" $outputstyle "silenceDeprecations" (slice "color-functions" "global-builtin" "import" "mixed-decls") "transpiler" "dartsass") }}
    {{ end }}

    {{ $resource = $resource | minify | fingerprint }}
    {{ $href = $resource.RelPermalink }}
    {{ $integrity = $resource.Data.Integrity }}
{{ else }}
    {{ $href = relLangURL $href }}
{{ end }}

<link {{ with $origin }} crossorigin="{{ . }}" {{ end }} href="{{ $href }}" {{ with $integrity }} integrity="{{ . }}" {{ end }} {{ with $policy }} referrerpolicy="{{ . }}" {{ end }} rel="stylesheet">
