1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-07-19 12:35:31 -04:00

bundle simple analytics script locally & minify everything with terser

This commit is contained in:
2020-04-27 20:49:20 -04:00
parent cb32af40dc
commit b0893ff52f
10 changed files with 497 additions and 27 deletions

View File

@@ -1,11 +1,9 @@
{{ $style := resources.Get "sass/main.scss" | resources.ExecuteAsTemplate "sass/main.scss" . | resources.ToCSS (dict "targetPath" "css/main.min.css") | resources.PostCSS (dict "config" "postcss.config.js") | resources.Fingerprint "sha256" }}
{{ $style := resources.Get "sass/main.scss" | resources.ExecuteAsTemplate "sass/main.scss" . | resources.ToCSS (dict "targetPath" "css/main.css") | resources.PostCSS (dict "config" "postcss.config.js") }}
<link rel="stylesheet" href="{{ $style.Permalink }}">
{{/* Page-specific styles set via front matter, scoped via SCSS */}}
{{ with .Params.css }}
{{- $target := path.Join $.File.Dir "css/inline.min.scss" }}
{{- $css := . | resources.FromString $target | resources.ToCSS | resources.PostCSS (dict "config" "postcss.config.js") | resources.Fingerprint "sha256" -}}
{{- $target := path.Join $.File.Dir "css/inline.scss" }}
{{- $css := . | resources.FromString $target | resources.ToCSS | resources.PostCSS (dict "config" "postcss.config.js") -}}
<link rel="stylesheet" href="{{ $css.Permalink }}">
{{ end }}

View File

@@ -1,5 +1,13 @@
{{ $darkmode := resources.Get "js/dark-mode.js" | resources.ExecuteAsTemplate "vendor/emoji/dark-mode.js" . }}
{{ $darkmode := resources.Get "js/dark-mode.js" | resources.ExecuteAsTemplate "js/dark-mode.js" . }}
{{ $twemoji := resources.Get "vendor/emoji/emoji.js" | resources.ExecuteAsTemplate "vendor/emoji/emoji.min.js" . }}
{{ $analytics := resources.Get "js/simple-analytics.js" | resources.ExecuteAsTemplate "js/simple-analytics.js" . }}
{{ $js := slice $darkmode $twemoji | resources.Concat "/js/main.js" | resources.Minify | resources.Fingerprint "sha256" }}
<script async defer {{ printf "src=%q integrity=%q" $js.Permalink $js.Data.Integrity | safeHTMLAttr }}></script>
{{ $bundle := "" }}
{{ if eq hugo.Environment "development" }}
{{ $bundle = slice $darkmode $twemoji }}
{{ else }}
{{ $bundle = slice $darkmode $twemoji $analytics }}
{{ end }}
{{ $js := $bundle | resources.Concat "/js/app.js" }}
<script async defer src="{{ $js.Permalink }}"></script>

View File

@@ -1,2 +0,0 @@
<script async defer src="https://s.jarv.is/latest.js" data-skip-dnt="true"></script>
<noscript><img src="https://s.jarv.is/image.gif" alt=""></noscript>