Skip to content

Commit

Permalink
Add preloading
Browse files Browse the repository at this point in the history
  • Loading branch information
Ipstenu committed Oct 8, 2024
1 parent cfcf06b commit b9334c1
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
41 changes: 41 additions & 0 deletions layouts/partials/head/head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{{ define "head" }}
{{- $version := strings.TrimPrefix "v" (partialCached "assets/version.html" .) -}}
{{ $desc := .Page.Description | default (.Page.Content | safeHTML | truncate 150) -}}
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
{{ hugo.Generator }}
<meta name="theme" content="{{ printf "Hinode %s" $version }}">
{{ partialCached "head/stylesheet-core.html" . -}}

{{ $config := page.Scratch.Get "modules" }}
{{ if not $config }}
{{ errorf "partial [head/head.html] - Cannot initialize module configuration" }}
{{ end }}

{{ $page_modules := slice | append .Page.Params.modules }}
{{ with .Scratch.Get "dependencies" }}{{ $page_modules = append $page_modules . | uniq }}{{ end }}
{{- $modules := $config.optional | intersect $page_modules -}}
{{- range $index, $mod := $modules -}}
{{- $source := printf "scss/%s.scss" $mod -}}
{{- $target := printf "css/%s.css" $mod -}}
{{- partial "head/stylesheet.html" (dict "source" $source "target" $target "core" false "page" .) }}
{{- end -}}

{{- if hasPrefix (lower .Site.Params.style.themeFontPath) "http" -}}
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="{{ .Site.Params.style.themeFontPath | default "https://fonts.googleapis.com/css2?family=Inter:wght@200;300;600&display=swap" }}">
{{ else if .Site.Params.style.themeFontPreload }}
{{ $font := partial "utilities/GetStaticURL" (dict "url" .Site.Params.style.themeFontPreload) }}
<link rel="preload" href="{{ $font }}" as="font" type="font/{{ strings.TrimPrefix "." (path.Ext $font) }}" crossorigin>
{{- end -}}

{{ partial "head/preload.html" . }}

{{ partial "head/seo.html" . }}
{{ partialCached "head/favicon.html" . -}}

{{ if gt (len .Site.Languages) 1}}
<meta name="lang" content="{{ .Site.Language }}">
{{ end }}
{{ end }}
7 changes: 7 additions & 0 deletions layouts/partials/head/preload.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{ $photogallery := .Page.Params.photogallery }}

{{ if $photogallery }}
{{ range $photogallery }}
<link rel="preload" href="{{ . }}" as="image" crossorigin>
{{ end }}
{{ end }}

0 comments on commit b9334c1

Please sign in to comment.