The way whitespace is handled in Hugo templates is difficult to understand. I accidentally pushed a broken version to production. This fixes the issue and improves the formatting of the template code.
40 lines
1.2 KiB
HTML
40 lines
1.2 KiB
HTML
{{/*
|
|
|
|
Emit an HTML script element referring to a JavaScript resource. The resource can
|
|
be either a path or a Hugo Resource object. If the former, the resource will be
|
|
looked up and built.
|
|
|
|
@context {string|Resource} resource
|
|
The Resource
|
|
@context {bool} minify
|
|
If true and the resource is a string, it will be minified as part of the build
|
|
step.
|
|
@context {bool} module
|
|
If true, add information to the script element indicating it should be loaded
|
|
as a module
|
|
|
|
*/}}
|
|
|
|
{{- $resource := .resource -}}
|
|
{{- $shouldMinify := .minify -}}
|
|
{{- $isModule := .module | default false -}}
|
|
|
|
{{- if eq (printf "%T" $resource) "string" }}
|
|
{{
|
|
$resource = partial "resource_builders/build_js.html"
|
|
(dict "resource" $resource "minify" $shouldMinify)
|
|
}}
|
|
{{- end -}}
|
|
|
|
{{- with $resource }}
|
|
{{- if eq hugo.Environment "development" }}
|
|
<script src="{{ .RelPermalink }}"
|
|
{{- if $isModule }} type="module"{{ end -}}
|
|
></script>
|
|
{{- else }}
|
|
<script src="{{ .RelPermalink }}" crossorigin="anonymous"
|
|
{{- if $isModule }} type="module"{{ end }}
|
|
{{- with .Data.Integrity }} integrity="{{ . }}"{{ end -}}
|
|
></script>
|
|
{{- end }}
|
|
{{- end -}}
|