{{ $params := . }}

{{ $crossorigin := $params.crossorigin | default "anonymous" }}
{{ $defer := $params.defer | default "defer" }}
{{ $integrity := $params.integrity }}
{{ $onload := $params.onload | safeJS }}
{{ $page := $params.page }}
{{ $referrerpolicy := $params.referrerpolicy | default "no-referrer" }}
{{ $src := $params.src }}
{{ $type := $params.type }}

{{ if not $src }}
    {{ errorf "paige/script: no src" }}
{{ end }}

{{ with partial "paige/resource.html" (dict "page" $page "url" $src) }}
    {{ $resource := . | minify | fingerprint }}
    {{ $integrity = $resource.Data.Integrity }}
    {{ $src = $resource.RelPermalink }}
{{ else }}
    {{ $src = relLangURL $src }}
{{ end }}

<script {{ with $crossorigin }} crossorigin="{{ . }}" {{ end }} {{ with $defer }} defer {{ end }} integrity="{{ $integrity }}" {{ with $onload }} onload="{{ . }}" {{ end }} {{ with $referrerpolicy }} referrerpolicy="{{ . }}" {{ end }} src="{{ $src | safeURL }}" {{ with $type }} {{ printf `type="%v"` . | safeHTMLAttr }} {{ end }}></script>
