Hi there,
I faced a very strange issue.
All my website is generated in HTML format and was working fine.
But I get the issue when I added a PHP format for a contact form.
Hugo version is v0.81
I use a partial to load my resources, here is the code :
{{/*
Loads a resources
Example :
{{ partial "tools/resource-load.html" (dict "Page" . "resource" $resourcevar) }}
{{ partial "tools/resource-load.html" (dict "Page" . "resource" $resourcevar "option" "onload=\"renderMathInElement(document.body,{throwOnError:false});\"") }}
Parameters :
- Page is the current page '.' context
- resource is a resource variable
- option is a string to add in final tag
*/}}
{{- $resource := .resource -}}
{{- $restype := (string $resource.MediaType) -}}
{{- $resintegrity := false -}}
{{- $relbase := "" -}}
{{- if eq $restype "text/css" -}}
{{- $resource = $resource | resources.PostCSS (dict "config" "assets/cfg/") -}}
{{- end -}}
{{- if .Page.Param "res-minify" -}}
{{- $resource = $resource | resources.Minify -}}
{{- end -}}
{{- if .Page.Param "res-fingerprint" -}}
{{- $resource = $resource | resources.Fingerprint (.Page.Param "res-hash") -}}
{{- $resintegrity = true -}}
{{- end -}}
{{- if eq $restype "text/css" -}}
{{- if .Page.Param "res-postprocess" -}}
{{- $resource = $resource | resources.PostProcess -}}
{{- end -}}
{{- end -}}
{{- if eq $restype "application/javascript" -}}
<script defer src="{{ $resource.RelPermalink }}" {{- if $resintegrity }} integrity="{{ $resource.Data.Integrity }}"{{ end -}} {{- with .option }} {{ . | safeHTMLAttr }}{{ end -}}></script>
{{ else if eq $restype "text/css" -}}
<link rel="stylesheet" href="{{ $relbase }}{{ $resource.RelPermalink }}" {{- if $resintegrity }} integrity="{{ $resource.Data.Integrity }}"{{ end -}} {{- with .option }} {{ . | safeHTMLAttr }}{{ end -}}>
{{- else -}}
{{ errorf "Cannot load resource %s, resource type %s is not compatible" $resource $resource.MediaType }}
{{- end -}}
HTML output for that partial is
<link rel=stylesheet href=/css/konidocs.min.0daeee14164f8f28b32af1ac3cbb6f28e0a560209ff443264ab8e9c6427233aa.css integrity=sha256-Da7uFBZPjyizKvGsPLtvKOClYCCf9EMmSrjpxkJyM6o=>
This is normal
PHP output for that partial is
<link rel=stylesheet href=__h_pp_l1_1_RelPermalink__e integrity=__h_pp_l1_1_Data.Integrity__e>
This is a failure
For information, I duplicated my layouts baseof.html and single.html to baseof.php and single.php
So the resources-load.html partial is called twice with the same resource.
By checking my partial, I found that issue was located inside the PostProcess block. I managed to fix the issue by changing my partial and moving postprocess part to the end.
It looks like an issue, please check if you need more data from my side.
Regards.