1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-12-03 03:48:55 -05:00

add a partial template that returns an asset's URL and hash from webpack's manifest

still a mess but slightly more modular. also added a real 404 page.
This commit is contained in:
2021-09-03 11:16:27 -04:00
parent a304fa5079
commit 3a3849e8ec
13 changed files with 97 additions and 111 deletions

View File

@@ -1,5 +1,5 @@
{{ printf "<!-- htmlmin:ignore -->" | safeHTML -}}
{{ printf "<!-- %s -->" hugo.Environment | safeHTML }}
{{ printf "<!-- %s -->" hugo.Version | safeHTML }}
{{ printf "<!-- /content/%s -->" .File.Path | safeHTML }}
{{ with hugo }}{{ printf "<!-- %s -->" .Environment | safeHTML }}
{{ printf "<!-- %s -->" .Version | safeHTML }}{{ end }}
{{ with .File }}{{ printf "<!-- /content/%s -->" .Path | safeHTML }}{{ end }}
{{- printf "<!-- htmlmin:ignore -->" | safeHTML }}

View File

@@ -1,10 +1,8 @@
{{/* Pull in CSS processed by Webpack */}}
{{- define "__head_css" -}}
{{ with .Site.Data.manifest }}
{{ with index . "main.css" }}
<link rel="stylesheet" href="{{ .src | absURL }}">
{{ end }}
{{ with partial "functions/webpack" (dict "context" . "src" "main.css") }}
<link rel="stylesheet" href="{{ .src }}">
{{ end }}
{{/* Page-specific styles set via front matter, piped through PostCSS and inlined */}}

View File

@@ -1,25 +1,23 @@
{{/* Pull in JS processed by Webpack */}}
{{- define "__head_preload" -}}
{{ with .Site.Data.manifest }}
{{ with index . "fonts/inter-subset.var.woff2" }}
<link rel="preload" href="{{ .src | absURL }}" as="font" type="font/woff2" crossorigin>
{{ end }}
{{ with index . "fonts/roboto-mono-subset.var.woff2" }}
<link rel="preload" href="{{ .src | absURL }}" as="font" type="font/woff2" crossorigin>
{{ end }}
{{ with index . "main.js" }}
<link rel="preload" href="{{ .src | absURL }}" as="script">
{{ end }}
{{ with partial "functions/webpack" (dict "context" . "src" "fonts/inter-subset.var.woff2") }}
<link rel="preload" href="{{ .src }}" as="font" type="font/woff2" crossorigin>
{{ end }}
{{ with partial "functions/webpack" (dict "context" . "src" "fonts/roboto-mono-subset.var.woff2") }}
<link rel="preload" href="{{ .src }}" as="font" type="font/woff2" crossorigin>
{{ end }}
{{ with partial "functions/webpack" (dict "context" . "src" "main.js") }}
<link rel="preload" href="{{ .src }}" as="script">
{{ end }}
{{- end -}}
{{- define "__body_js" -}}
{{ with .Site.Data.manifest }}
{{ with index . "main.js" -}}
<script async defer src="{{ .src | absURL }}"></script>
{{ end -}}
{{ end -}}
{{ with partial "functions/webpack" (dict "context" . "src" "main.js") }}
<script async defer src="{{ .src }}"></script>
{{ end }}
{{/* Detect shortcodes and append external scripts as needed once per page */}}
{{ if .HasShortcode "gh-buttons" -}}

View File

@@ -15,10 +15,8 @@
{{/* Chooses and initializes various images for use by JSON schema & open graph tags */}}
{{/* Author image (default) */}}
{{- with .Site.Data.manifest -}}
{{- with index . $.Site.Author.image -}}
{{- $.Scratch.Set "authorImage" (dict "Permalink" (absURL .src) "Width" 1200 "Height" 1200 "MediaType" "image/jpeg") -}}
{{- end -}}
{{- with partial "functions/webpack" (dict "context" . "src" .Site.Author.image) -}}
{{- $.Scratch.Set "authorImage" (dict "Permalink" .src "Width" 1200 "Height" 1200 "MediaType" "image/jpeg") -}}
{{- end -}}
{{/* Page image (via frontmatter) */}}
{{- with .Params.image -}}
@@ -31,9 +29,8 @@
{{- $.Scratch.Set "pageImage" . -}}
{{- end -}}
{{- end -}}
{{/* Site logo */}}
{{- with .Site.Data.manifest -}}
{{- with index . $.Site.Params.image -}}
{{- $.Scratch.Set "logoImage" (dict "Permalink" (absURL .src) "Width" 2048 "Height" 2048 "MediaType" "image/png") -}}
{{- end -}}
{{- with partial "functions/webpack" (dict "context" . "src" .Site.Params.image) -}}
{{- $.Scratch.Set "logoImage" (dict "Permalink" .src "Width" 2048 "Height" 2048 "MediaType" "image/png") -}}
{{- end -}}

View File

@@ -0,0 +1,13 @@
{{/* Returns the URL and hash of an asset processed by Webpack */}}
{{/* Usage: pass in (dict "context" . "src" "images/tiny-selfie.jpg"), returns .src = "/assets/images/tiny-selfie.jpg", .integrity = "sha384-asdfjklsemicolon" */}}
{{ $src := .src }}
{{ $data := "" }}
{{ with .context.Site.Data.manifest }}
{{ with index . $src }}
{{ $data = . }}
{{ end }}
{{ end }}
{{ return $data }}