refactor(plugin/style.html): improve code formatting and indentation for better readability

This commit is contained in:
Sped0n
2023-10-30 15:57:13 +08:00
parent 0b350db741
commit 1632803e91

View File

@@ -1,36 +1,58 @@
{{- if strings.HasPrefix .Source "<link" -}}
{{- safeHTML .Source -}}
{{- safeHTML .Source -}}
{{- else -}}
{{- $href := .Source -}}
{{- $integrity := .Integrity -}}
{{- $resource := 0 -}}
{{- if $href | and (not (urls.Parse $href).Host) -}}
{{- $resource = resources.Get $href -}}
{{- $href := .Source -}}
{{- $integrity := .Integrity -}}
{{- $resource := 0 -}}
{{- if $href | and (not (urls.Parse $href).Host) -}}
{{- $resource = resources.Get $href -}}
{{- end -}}
{{- with .Content -}}
{{- $resource = resources.FromString $.Path . -}}
{{- end -}}
{{- if $resource -}}
{{- with .Template -}}
{{- $resource = $resource | resources.ExecuteAsTemplate . $.Context -}}
{{- end -}}
{{- with .ToCSS -}}
{{- $options := . | merge (dict "outputStyle" "compressed") -}}
{{- $resource = $resource | toCSS $options -}}
{{- end -}}
{{- if .Minify -}}
{{- $resource = $resource | minify -}}
{{- end -}}
{{- with .Fingerprint -}}
{{- $resource = $resource | fingerprint . -}}
{{- $integrity = $resource.Data.Integrity -}}
{{- end -}}
{{- $href = $resource.RelPermalink -}}
{{- end -}}
{{- if .Defer -}}
<link
rel="preload"
as="style"
onload="this.onload=null;this.rel='stylesheet'"
href="{{ $href }}"
{{ if .Crossorigin }}crossorigin="anonymous"{{ end }}{{ with $integrity }}
integrity="{{ . }}"
{{ end }}{{ with .Attr }}{{ . | safeHTMLAttr }}{{ end }}
/>
<noscript
><link
rel="stylesheet"
href="{{ $href }}"
{{ if .Crossorigin }}crossorigin="anonymous"{{ end }}{{ with $integrity }}
integrity="{{ . }}"
{{ end }}{{ with .Attr }}{{ . | safeHTMLAttr }}{{ end }}
/></noscript>
{{- else -}}
<link
rel="stylesheet"
href="{{ $href }}"
{{ if .Crossorigin }}crossorigin="anonymous"{{ end }}{{ with $integrity }}
integrity="{{ . }}"
{{ end }}{{ with .Attr }}{{ . | safeHTMLAttr }}{{ end }}
/>
{{- end -}}
{{- end -}}
{{- with .Content -}}
{{- $resource = resources.FromString $.Path . -}}
{{- end -}}
{{- if $resource -}}
{{- with .Template -}}
{{- $resource = $resource | resources.ExecuteAsTemplate . $.Context -}}
{{- end -}}
{{- with .ToCSS -}}
{{- $options := . | merge (dict "outputStyle" "compressed") -}}
{{- $resource = $resource | toCSS $options -}}
{{- end -}}
{{- if .Minify -}}
{{- $resource = $resource | minify -}}
{{- end -}}
{{- with .Fingerprint -}}
{{- $resource = $resource | fingerprint . -}}
{{- $integrity = $resource.Data.Integrity -}}
{{- end -}}
{{- $href = $resource.RelPermalink -}}
{{- end -}}
{{- if .Defer -}}
<link rel="preload" as="style" onload="this.onload=null;this.rel='stylesheet'" href="{{ $href }}"{{ if .Crossorigin }} crossorigin="anonymous"{{ end }}{{ with $integrity }} integrity="{{ . }}"{{ end }}{{ with .Attr }} {{ . | safeHTMLAttr }}{{ end }}>
<noscript><link rel="stylesheet" href="{{ $href }}"{{ if .Crossorigin }} crossorigin="anonymous"{{ end }}{{ with $integrity }} integrity="{{ . }}"{{ end }}{{ with .Attr }} {{ . | safeHTMLAttr }}{{ end }}></noscript>
{{- else -}}
<link rel="stylesheet" href="{{ $href }}"{{ if .Crossorigin }} crossorigin="anonymous"{{ end }}{{ with $integrity }} integrity="{{ . }}"{{ end }}{{ with .Attr }} {{ . | safeHTMLAttr }}{{ end }}>
{{- end -}}
{{- end -}}