Sfoglia il codice sorgente

Fix customJS and customCSS feature (#606)

* Fix customJS function

In the current state the customJS feature doesn't work, because an asset will only be generated to `/public` when `.RelPermalink` is used as mentioned in the [document](https://gohugo.io/hugo-pipes/introduction/#asset-publishing).

* Update CONTRIBUTORS.md

* Fix customCSS as well
Simon Pai 4 anni fa
parent
commit
1cdbe4f14a
2 ha cambiato i file con 15 aggiunte e 2 eliminazioni
  1. 1 0
      CONTRIBUTORS.md
  2. 14 2
      layouts/_default/baseof.html

+ 1 - 0
CONTRIBUTORS.md

@@ -103,3 +103,4 @@
 - [Kirill Feoktistov](https://feoktistoff.org)
 - [leins275](https://github.com/LanskovNV)
 - [Michael Weiss](https://mweiss.ch)
+- [Simon Pai](https://github.com/simonpai)

+ 14 - 2
layouts/_default/baseof.html

@@ -61,7 +61,13 @@
     {{ end }}
 
     {{ range .Site.Params.customCSS }}
-      <link rel="stylesheet" href="{{ . | relURL }}" />
+      {{ if $.Site.IsServer }}
+        {{ $styles := resources.Get . }}
+        <link rel="stylesheet" href="{{ $styles.RelPermalink }}" media="screen">
+      {{ else }}
+        {{ $styles := resources.Get . | minify | fingerprint }}
+        <link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Integrity }}" crossorigin="anonymous" media="screen" />
+      {{ end }}
     {{ end }}
 
     {{ range .Site.Params.customSCSS }}
@@ -123,7 +129,13 @@
     {{ end }}
 
     {{ range .Site.Params.customJS }}
-      <script src="{{ . | relURL }}"></script>
+      {{ if $.Site.IsServer }}
+        {{ $script := resources.Get . }}
+        <script src="{{ $script.RelPermalink }}"></script>
+      {{ else }}
+        {{ $script := resources.Get . | minify | fingerprint }}
+        <script src="{{ $script.RelPermalink }}" integrity="{{ $script.Data.Integrity }}"></script>
+      {{ end }}
     {{ end }}
 
     {{ template "_internal/google_analytics.html" . }}