mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2025-04-26 14:28:25 -04:00
also migrated SASS to latest syntax (via dart-sass) and vastly simplified light/dark theme logic
83 lines
3.6 KiB
HTML
83 lines
3.6 KiB
HTML
{{/* Pull in assets processed by Webpack */}}
|
|
{{- define "__head_css" -}}
|
|
{{ with .Site.Data.manifest }}
|
|
{{ with index . "main.css" }}
|
|
<link rel="stylesheet" href="{{ .src | absURL }}">
|
|
{{ end }}
|
|
{{ end }}
|
|
|
|
{{/* Page-specific styles set via front matter, piped through PostCSS and inlined */}}
|
|
{{- with .Params.css -}}
|
|
{{/* NOTE: This file doesn't end up getting published (which is good) */}}
|
|
{{- $target := path.Join $.File.Dir "css/inline.scss" -}}
|
|
{{- $css := . | resources.FromString $target | resources.PostCSS (dict "config" "postcss.config.js") -}}
|
|
<style>
|
|
{{ $css.Content | safeCSS }}
|
|
</style>
|
|
{{- end -}}
|
|
{{- end -}}
|
|
|
|
{{- 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 }}
|
|
{{ end }}
|
|
{{- end -}}
|
|
|
|
{{- define "__body_js" -}}
|
|
<!-- inline the dark mode script to avoid a blinding flash of white background on loads -->
|
|
<script>(function(d){var u=d.document,f=u.body.classList,e=localStorage,c="dark_mode_pref",t=e.getItem(c),a="dark",n="light",r="{{ .Site.Params.Theme.defaultTheme | safeJS }}",o=u.querySelector(".dark-mode-toggle"),i=r===a,b=function(d){f.remove(a,n);f.add(d);i=d===a};t===a&&b(a);t===n&&b(n);if(!t){var s=function(d){return"(prefers-color-scheme: "+d+")"};d.matchMedia(s(a)).matches?b(a):d.matchMedia(s(n)).matches?b(n):b(r);d.matchMedia(s(a)).addListener((function(d){d.matches&&b(a)}));d.matchMedia(s(n)).addListener((function(d){d.matches&&b(n)}))}if(o){o.style.display="block";o.addEventListener("click",(function(){if(i){b(n);e.setItem(c,n)}else{b(a);e.setItem(c,a)}}),!0)}})(window)</script>
|
|
|
|
{{ with .Site.Data.manifest }}
|
|
{{ with index . "main.js" }}
|
|
<script async defer src="{{ .src | absURL }}" ></script>
|
|
{{ end }}
|
|
{{ end }}
|
|
{{- end -}}
|
|
|
|
|
|
{{/* Strip any markdown styling from page title for use in meta tags */}}
|
|
{{- with .Title -}}
|
|
{{- $.Scratch.Set "plainTitle" (. | markdownify | htmlUnescape | plainify) -}}
|
|
{{- end -}}
|
|
|
|
|
|
{{/* If this is a page/post, link View Source to specific file on GitHub; otherwise, just link to repo homepage */}}
|
|
{{- with .Site.Params.social.githubRepo }}
|
|
{{- $githubURL := print "https://github.com/" . }}
|
|
{{- if not $.IsPage }}
|
|
{{- $.Scratch.Set "sourceURL" $githubURL }}
|
|
{{- else }}
|
|
{{- $.Scratch.Set "sourceURL" (print $githubURL "/blob/main/content/" $.File.Path) }}
|
|
{{- end }}
|
|
{{- end }}
|
|
|
|
|
|
{{/* Chooses and initializes various images for use by JSON schema & open graph tags */}}
|
|
{{/* Author image (default) */}}
|
|
{{- with index .Site.Data.manifest .Site.Author.image -}}
|
|
{{- $.Scratch.Set "authorImage" (dict "Permalink" (absURL .src) "Width" 1200 "Height" 1200 "MediaType" "image/jpeg") -}}
|
|
{{- end -}}
|
|
{{/* Page image (via frontmatter) */}}
|
|
{{- with .Params.image -}}
|
|
{{- with $.Page.Resources.GetMatch . -}}
|
|
{{- $.Scratch.Set "pageImage" . -}}
|
|
{{- end -}}
|
|
{{- else -}}
|
|
{{/* Fallback to author image set above */}}
|
|
{{- with $.Scratch.Get "authorImage" -}}
|
|
{{- $.Scratch.Set "pageImage" . -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{/* Site logo */}}
|
|
{{- with index .Site.Data.manifest .Site.Params.image -}}
|
|
{{- $.Scratch.Set "logoImage" (dict "Permalink" (absURL .src) "Width" 2048 "Height" 2048 "MediaType" "image/png") -}}
|
|
{{- end -}}
|