♻️ Refactor: plugin script

This commit is contained in:
Cell
2022-09-12 19:42:44 +08:00
parent f9b92cbbd6
commit 5750079022
2 changed files with 25 additions and 8 deletions
+1
View File
@@ -24,6 +24,7 @@ All notable changes to this project will be documented in this file.
- :recycle: Refactor: back to top and scroll to comments
- :recycle: Refactor: custom.js rendering and remove `params.customJS` ([#189](https://github.com/hugo-fixit/FixIt/pull/189))
- :recycle: Refactor: scss directory ([#185](https://github.com/hugo-fixit/FixIt/issues/185))
- :recycle: Refactor: plugin script
- :bug: Fix: add function `dos2unix` to unify new lines symbol between Windows and Unix/Mac OS
- :bug: Fix: author display error in post and markdown file
- :bug: Fix: use data attributes or class replace for custom attributes
+24 -8
View File
@@ -1,11 +1,11 @@
{{- if .Content -}}
<script>{{- .Content | safeJS -}}</script>
{{- else if strings.HasPrefix .Source "<script" -}}
{{- safeHTML .Source -}}
{{- with .Content -}}
<script>{{ . | safeJS }}</script>
{{- else -}}
{{- $src := .Source -}}
{{- $integrity := .Integrity -}}
{{- if $src -}}
{{- if strings.HasPrefix .Source "<script" -}}
{{- safeHTML .Source -}}
{{- else -}}
{{- $src := .Source -}}
{{- $integrity := .Integrity -}}
{{- if (urls.Parse $src).Host | not -}}
{{- $resource := resources.Get $src -}}
{{- with .Template -}}
@@ -20,6 +20,22 @@
{{- end -}}
{{- $src = $resource.RelPermalink -}}
{{- end -}}
<script src="{{ $src }}"{{ if .Crossorigin }} crossorigin="anonymous"{{ end }}{{ with $integrity }} integrity="{{ . }}"{{ end }}{{ if .Async }} async{{ end }}{{ if .Defer }} defer{{ end }}{{ with .Attr }} {{ . | safeHTMLAttr }}{{ end }}></script>
{{- $attrs := printf `src="%v"` $src -}}
{{- if .Crossorigin -}}
{{- $attrs = ` crossorigin="anonymous"` | add $attrs -}}
{{- end -}}
{{- with $integrity -}}
{{- $attrs = printf ` integrity="%v"` . | add $attrs -}}
{{- end -}}
{{- if .Async -}}
{{- $attrs = " async" | add $attrs -}}
{{- end -}}
{{- if .Defer -}}
{{- $attrs = " defer" | add $attrs -}}
{{- end -}}
{{- with .Attr -}}
{{- $attrs = add " " . | add $attrs -}}
{{- end -}}
<script {{ $attrs | safeHTMLAttr }}></script>
{{- end -}}
{{- end -}}