Skip to content

Commit

Permalink
feat: use Hugo's built-in minification pipeline
Browse files Browse the repository at this point in the history
- Update head.html to use Hugo's resource.Minify for CSS and JS
- Add fingerprinting for cache busting
- Add integrity hashes for security
- Implement proper asset pipeline for custom CSS
  • Loading branch information
RileySeaburg committed Dec 3, 2024
1 parent 22203c7 commit 73b32d8
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions themes/digital.gov/layouts/partials/core/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -218,23 +218,36 @@
{{- end -}}

{{ "<!-- CSS -->" | safeHTML }}
{{/* Custom CSS — needs to be included before the base styles */}}
{{/* Custom CSSneeds to be included before the base styles */}}
{{- if $.Params.css -}}
{{- range $.Params.css -}}
{{- $path := (printf "dist/%s" .) | absURL -}}
{{- $customCSS := resources.Get (printf "dist/%s" .) -}}
{{- $customCSSMinified := $customCSS | resources.Minify -}}
<!-- CUSTOM CSS -->
<link rel="stylesheet" media="all" href="{{- $path -}}" type="text/css" />
<link rel="stylesheet" media="all" href="{{- $customCSSMinified.RelPermalink -}}" type="text/css" />
{{- end -}}
{{- end -}}

{{/* Base styles */}}
{{- $styles := resources.Get "dist/styles.css" -}}
{{- $stylesMinified := $styles | resources.Minify | resources.Fingerprint -}}
<link
rel="stylesheet"
href="{{- "dist/styles.css" | absURL -}}"
href="{{- $stylesMinified.RelPermalink -}}"
type="text/css"
media="all"
integrity="{{ $stylesMinified.Data.Integrity }}"
crossorigin="anonymous"
/>
<script src="{{ "dist/js/uswds-init.min.js" | absURL }}"></script>

{{/* USWDS Init JS */}}
{{- $uswdsInit := resources.Get "dist/js/uswds-init.min.js" -}}
{{- $uswdsInitMinified := $uswdsInit | resources.Minify | resources.Fingerprint -}}
<script
src="{{ $uswdsInitMinified.RelPermalink }}"
integrity="{{ $uswdsInitMinified.Data.Integrity }}"
crossorigin="anonymous"
></script>

{{ "<!-- Favicons & Icons -->" | safeHTML }}
<link
Expand Down

0 comments on commit 73b32d8

Please sign in to comment.