Skip to content

Commit

Permalink
Do not minify/fingerprint assets in development
Browse files Browse the repository at this point in the history
  • Loading branch information
ldeso committed Jan 19, 2024
1 parent 46899dc commit 843c484
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 14 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -230,8 +230,8 @@ will cause `myscript.js` to be loaded on every page where `myshortcode` is used.
As a real-life example, this is the template for the built-in SoundCloud shortcode:

```html
{{ resources.Get "css/soundcloud.css" | minify | fingerprint | .Page.Scratch.SetInMap "css" "soundcloud" }}
{{ resources.Get "js/soundcloud.js" | minify | fingerprint | .Page.Scratch.SetInMap "js" "soundcloud" }}
{{ resources.Get "css/soundcloud.css" | .Page.Scratch.SetInMap "css" "soundcloud" }}
{{ resources.Get "js/soundcloud.js" | .Page.Scratch.SetInMap "js" "soundcloud" }}

<div class="Soundcloud">
<a href="{{ .Get 0 }}" target="_blank" class="Soundcloud-box Soundcloud-box--link"><span class="Soundcloud-ellipsis">{{ .Get 0 }}</span></a>
Expand Down
2 changes: 1 addition & 1 deletion layouts/_default/_markup/render-codeblock.html
@@ -1,4 +1,4 @@
{{ if eq site.Params.noClasses false }}
{{ resources.Get "css/syntax.css" | minify | fingerprint | .Page.Scratch.SetInMap "css" "syntax" }}
{{ resources.Get "css/syntax.css" | .Page.Scratch.SetInMap "css" "syntax" }}
{{ end }}
{{ highlight .Inner .Type .Options }}
16 changes: 14 additions & 2 deletions layouts/partials/assets.html
@@ -1,7 +1,19 @@
{{ range .Scratch.GetSortedMapValues "css" }}
<link rel="stylesheet" href="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous">
{{- if eq hugo.Environment "development" }}
<link rel="stylesheet" href="{{ .RelPermalink }}">
{{- else }}
{{- with . | minify | fingerprint }}
<link rel="stylesheet" href="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous">
{{- end }}
{{- end }}
{{ end }}

{{ range .Scratch.GetSortedMapValues "js" }}
<script defer src="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous"></script>
{{- if eq hugo.Environment "development" }}
<script defer src="{{ .RelPermalink }}"></script>
{{- else }}
{{- with . | minify | fingerprint }}
<script defer src="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous"></script>
{{- end }}
{{- end }}
{{ end }}
2 changes: 1 addition & 1 deletion layouts/shortcodes/contact.html
@@ -1,4 +1,4 @@
{{ resources.Get "css/contact.css" | minify | fingerprint | .Page.Scratch.SetInMap "css" "contact" }}
{{ resources.Get "css/contact.css" | .Page.Scratch.SetInMap "css" "contact" }}

<form class="Contact" name="contact" method="POST" data-netlify="true"{{ if site.Params.netlify.honeypot }} data-netlify-honeypot="bot"{{ end }}{{ if site.Params.netlify.recaptcha }} data-netlify-recaptcha="true"{{ end }}{{ with .Get 0 }} action="{{ . }}"{{ end }}>
<ul class="Contact-group">
Expand Down
12 changes: 6 additions & 6 deletions layouts/shortcodes/math.html
Expand Up @@ -10,11 +10,11 @@
{{ $resource.Publish }}
{{ end }}

{{ printf "%s/dist/katex.min.css" $katex | resources.GetRemote | minify | fingerprint | resources.Copy "css/katex.css" | .Page.Scratch.SetInMap "css" "math" }}
{{ printf "%s/dist/katex.min.js" $katex | resources.GetRemote | minify | fingerprint | resources.Copy "js/katex.js" | .Page.Scratch.SetInMap "js" "math-1" }}
{{ printf "%s/dist/contrib/auto-render.min.js" $katex | resources.GetRemote | minify | fingerprint | resources.Copy "js/auto-render.js" | .Page.Scratch.SetInMap "js" "math-2" }}
{{ resources.Get "js/math.js" | minify | fingerprint | .Page.Scratch.SetInMap "js" "math-3" }}
{{ printf "%s/dist/katex.min.css" $katex | resources.GetRemote | resources.Copy "css/katex.css" | .Page.Scratch.SetInMap "css" "math" }}
{{ printf "%s/dist/katex.min.js" $katex | resources.GetRemote | resources.Copy "js/katex.js" | .Page.Scratch.SetInMap "js" "math-1" }}
{{ printf "%s/dist/contrib/auto-render.min.js" $katex | resources.GetRemote | resources.Copy "js/auto-render.js" | .Page.Scratch.SetInMap "js" "math-2" }}
{{ resources.Get "js/math.js" | .Page.Scratch.SetInMap "js" "math-3" }}

{{ `<div class="Math">` | htmlUnescape | safeHTML }}
{{ htmlUnescape `<div class="Math">` | safeHTML }}
{{ .Inner }}
{{ "</div>" | htmlUnescape | safeHTML }}
{{ htmlUnescape "</div>" | safeHTML }}
4 changes: 2 additions & 2 deletions layouts/shortcodes/soundcloud.html
@@ -1,5 +1,5 @@
{{ resources.Get "css/soundcloud.css" | minify | fingerprint | .Page.Scratch.SetInMap "css" "soundcloud" }}
{{ resources.Get "js/soundcloud.js" | minify | fingerprint | .Page.Scratch.SetInMap "js" "soundcloud" }}
{{ resources.Get "css/soundcloud.css" | .Page.Scratch.SetInMap "css" "soundcloud" }}
{{ resources.Get "js/soundcloud.js" | .Page.Scratch.SetInMap "js" "soundcloud" }}

<div class="Soundcloud">
<a href="{{ .Get 0 }}" target="_blank" class="Soundcloud-box Soundcloud-box--link"><span class="Soundcloud-ellipsis">{{ .Get 0 }}</span></a>
Expand Down

0 comments on commit 843c484

Please sign in to comment.