From 294fa8343b1d03c3955deeae61948232704fb5e7 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Tue, 8 Nov 2022 17:45:38 -0800 Subject: [PATCH] Get all the fingerprinting done! - Add partials in the resources folder for each of the major resources of my site - Consolidate .css and .js files via resources.Concat where possible --- .gitignore | 2 +- assets/scripts/railroad-utils.js | 4 +-- {static => assets}/styles/development.css | 0 {content => assets/styles}/home.css | 0 {static => assets}/styles/monokai.css | 0 {static => assets}/styles/railroad.css | 0 layouts/_default/baseof.html | 36 +++++++++---------- layouts/_default/single.html | 14 ++------ layouts/partials/resources/page_css.html | 5 +++ .../partials/resources/railroad_utils.html | 4 +++ layouts/partials/resources/root_css.html | 11 ++++++ layouts/partials/resources/section_css.html | 11 ++++++ layouts/partials/resources/site_js.html | 2 ++ layouts/shortcodes/scripts/railroad.html | 8 ++--- 14 files changed, 58 insertions(+), 39 deletions(-) rename {static => assets}/styles/development.css (100%) rename {content => assets/styles}/home.css (100%) rename {static => assets}/styles/monokai.css (100%) rename {static => assets}/styles/railroad.css (100%) create mode 100644 layouts/partials/resources/page_css.html create mode 100644 layouts/partials/resources/railroad_utils.html create mode 100644 layouts/partials/resources/root_css.html create mode 100644 layouts/partials/resources/section_css.html create mode 100644 layouts/partials/resources/site_js.html diff --git a/.gitignore b/.gitignore index e791966..dc1c02a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ public/ -resources/ +/resources/ .hugo_build.lock *.log *.orig diff --git a/assets/scripts/railroad-utils.js b/assets/scripts/railroad-utils.js index 4086e5c..79b60e9 100644 --- a/assets/scripts/railroad-utils.js +++ b/assets/scripts/railroad-utils.js @@ -1,5 +1,5 @@ -{{ with partial "secure_asset.html" "scripts/lib/railroad.js" }} -import rr from "{{ .Secure.RelPermalink }}"; +{{ with resources.Get "scripts/lib/railroad.js" | fingerprint "sha512" }} +import rr from "{{ .RelPermalink }}"; {{ else }} {{ errorf "Unable to get railroad.js resource" }} {{ end }} diff --git a/static/styles/development.css b/assets/styles/development.css similarity index 100% rename from static/styles/development.css rename to assets/styles/development.css diff --git a/content/home.css b/assets/styles/home.css similarity index 100% rename from content/home.css rename to assets/styles/home.css diff --git a/static/styles/monokai.css b/assets/styles/monokai.css similarity index 100% rename from static/styles/monokai.css rename to assets/styles/monokai.css diff --git a/static/styles/railroad.css b/assets/styles/railroad.css similarity index 100% rename from static/styles/railroad.css rename to assets/styles/railroad.css diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 0f547f8..d3af73e 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -3,34 +3,30 @@ {{ partial "head.html" . }} - {{ block "body" . }} + {{ block "body" . -}} {{ block "header" . }}{{ end }}
{{ block "main" . }}{{ end }}
- {{ partial "development/page_info.html" . }} - {{ block "footer" . }}{{ end }} - {{ end }} + {{- partial "development/page_info.html" . -}} + {{- block "footer" . -}}{{- end -}} + {{- end -}} - {{- $rootCSS := resources.Get "styles/root.css" - | resources.ExecuteAsTemplate "root.css" . - | resources.Fingerprint "sha512" -}} - - {{ if not hugo.IsProduction }} - - {{ end }} - {{ with partial "secure_asset.html" (printf "styles/%s.css" .Section) }} - - {{ end }} - {{ range .Resources.Match "*.css" }} - - {{ end }} + {{ with partial "resources/root_css.html" . -}} + + {{- end -}} + {{- with partial "resources/section_css.html" . -}} + + {{- end -}} + {{- with partial "resources/page_css.html" . -}} + + {{- end -}} {{ block "styles" . }}{{ end }} {{ block "scripts" . }}{{ end }} - {{ $concatenatedSiteScript := resources.Get "scripts/site.js" - | resources.Fingerprint "sha512" }} - + {{- with partial "resources/site_js.html" . -}} + + {{ end }} diff --git a/layouts/_default/single.html b/layouts/_default/single.html index fb78001..b806f1c 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -6,20 +6,10 @@ {{ partial "single_main.html" . }} {{ end }} -{{ define "styles" }} - {{- if .HasShortcode "figures/railroad" -}} - - {{- end -}} - -{{ end }} - {{ define "scripts" }} {{- if .HasShortcode "figures/railroad" -}} - {{- with partial "secure_asset.html" "scripts/lib/railroad.js" -}} - - {{- end -}} - {{- with resources.Get "scripts/railroad-utils.js" -}} - + {{- with partial "resources/railroad_utils.html" . -}} + {{- end -}} {{- end -}} diff --git a/layouts/partials/resources/page_css.html b/layouts/partials/resources/page_css.html new file mode 100644 index 0000000..7b27bc8 --- /dev/null +++ b/layouts/partials/resources/page_css.html @@ -0,0 +1,5 @@ +{{ $pageCSS := dict }} +{{ with .Resources.Match "*.css" }} + {{ $pageCSS = . | resources.Concat "page.css" | fingerprint "sha512" }} +{{ end }} +{{ return $pageCSS }} diff --git a/layouts/partials/resources/railroad_utils.html b/layouts/partials/resources/railroad_utils.html new file mode 100644 index 0000000..475adbf --- /dev/null +++ b/layouts/partials/resources/railroad_utils.html @@ -0,0 +1,4 @@ +{{- $railroadUtilsJS := resources.Get "scripts/railroad-utils.js" + | resources.ExecuteAsTemplate "scripts/railroad_utils.js" . + | resources.Fingerprint "sha512" -}} +{{ return $railroadUtilsJS }} diff --git a/layouts/partials/resources/root_css.html b/layouts/partials/resources/root_css.html new file mode 100644 index 0000000..615c218 --- /dev/null +++ b/layouts/partials/resources/root_css.html @@ -0,0 +1,11 @@ +{{ $allStylesheets := slice (resources.Get "styles/root.css") + (resources.Get "styles/railroad.css") + (resources.Get "styles/monokai.css") }} +{{ if not hugo.IsProduction }} + {{ $allStylesheets = $allStylesheets | append (resources.Get "styles/development.css") }} +{{ end }} +{{ $rootCSS := $allStylesheets + | resources.Concat "styles/root.css" + | resources.ExecuteAsTemplate "styles/root.css" . + | fingerprint "sha512" }} +{{ return $rootCSS }} diff --git a/layouts/partials/resources/section_css.html b/layouts/partials/resources/section_css.html new file mode 100644 index 0000000..a1a053e --- /dev/null +++ b/layouts/partials/resources/section_css.html @@ -0,0 +1,11 @@ +{{ $sectionCSS := dict }} +{{ $sectionStylesheet := "" }} +{{ if .IsHome }} + {{ $sectionStylesheet = printf "styles/home.css" }} +{{ else }} + {{ $sectionStylesheet = printf "styles/%s.css" .Section }} +{{ end }} +{{ with resources.Get $sectionStylesheet }} + {{ $sectionCSS = . | fingerprint "sha512" }} +{{ end }} +{{ return $sectionCSS }} diff --git a/layouts/partials/resources/site_js.html b/layouts/partials/resources/site_js.html new file mode 100644 index 0000000..5b5ccb5 --- /dev/null +++ b/layouts/partials/resources/site_js.html @@ -0,0 +1,2 @@ +{{ $siteJS := resources.Get "scripts/site.js" | fingerprint "sha512" }} +{{ return $siteJS }} diff --git a/layouts/shortcodes/scripts/railroad.html b/layouts/shortcodes/scripts/railroad.html index 26a048f..236033e 100644 --- a/layouts/shortcodes/scripts/railroad.html +++ b/layouts/shortcodes/scripts/railroad.html @@ -1,8 +1,8 @@ -{{- $parentID := .Parent.Get "id" -}} -{{- $narrowOnly := .Get "narrow" }} +{{ $parentID := .Parent.Get "id" -}} +{{ $narrowOnly := not (not (.Get "narrow")) | default false }}