Get the line breaking situation working correctly

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.
This commit is contained in:
Eryn Wells 2024-11-14 08:49:09 -08:00
parent 73e3cec711
commit 31acd82fd8
2 changed files with 16 additions and 16 deletions

View file

@ -1,6 +1,7 @@
{{- $resourcePath := .resource -}}
{{- $minify := .minify | default true -}}
{{- $resource := dict -}}
{{- with resources.Get $resourcePath }}
{{- if eq hugo.Environment "development" }}
{{- with . | js.Build }}
@ -12,7 +13,7 @@
{{ $resource = . }}
{{- end }}
{{- end }}
{{ else }}
{{- else }}
{{ warnf "Unable to find JavaScript resource: %s" $resourcePath }}
{{- end }}

View file

@ -19,23 +19,22 @@ looked up and built.
{{- $shouldMinify := .minify -}}
{{- $isModule := .module | default false -}}
{{ if eq (printf "%T" $resource) "string" }}
{{- if eq (printf "%T" $resource) "string" }}
{{
$resource = partial "resource_builders/build_js.html"
(dict "resource" $resource "minify" $shouldMinify)
}}
{{ end }}
{{- end -}}
{{ with $resource }}
{{ if eq hugo.Environment "development" }}
<script {{ if $isModule }}type="module"{{ end }} src="{{ .RelPermalink }}"></script>
{{ else }}
<script
{{- if $isModule }} type="module" {{ end -}}
src="{{ .RelPermalink }}"
{{- with .Data.Integrity }} integrity="{{ . }}" {{ end -}}
crossorigin="anonymous"
{{- "" -}}>
</script>
{{ end }}
{{ 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 -}}