Move head partials in to a head sub dir. Create a footer.html partial.

This commit is contained in:
Fredrik Jonsson 2025-04-11 15:19:07 +02:00
commit 8b2a439df5
12 changed files with 17 additions and 21 deletions

View file

@ -379,9 +379,9 @@ The theme will autodetect them and add the needed code.
### Head and footer partials
If you create partials named `head.html` and/or `footer.html` they will be used. They do not exist in the theme but are supported as a convenience.
If you create partials named `head/extra.html` and/or `footer.html` they will be used. They do not exist or are empty in the theme but are supported as a convenience.
Content in the "head" partial will be added to the end of the "head" tag, perhaps some extra css or javascript.
Content in the "head/extra" partial will be added to the end of the "head" tag, perhaps some extra css or javascript.
Content in the "footer" partial will replace all the default content in the "footer" tag.

View file

@ -0,0 +1,4 @@
{{ if $.Param "feedlinks" }}{{ partial "feedlinks.html" . }}{{ end -}}
<p>{{ with site.Copyright }}{{ . | site.Home.RenderString }}{{ else }}<span>© {{ site.Title }}</span>{{ end }}</p>
{{ with $.Param "footer" }}<p>{{ . | site.Home.RenderString }}</p>{{ end }}
{{ if $.Param "poweredby" }}<p>Powered by <a href="https://gohugo.io/">Hugo</a> and the <a href="https://github.com/frjo/hugo-theme-zen">Zen theme</a>.</p>{{ end }}

View file

@ -0,0 +1 @@

View file

@ -0,0 +1,17 @@
{{ if fileExists (path.Join "/static" "apple-touch-icon.png") -}}
<link rel="apple-touch-icon" href="{{ "apple-touch-icon.png" | relURL }}">
{{ end -}}
{{ if fileExists (path.Join "/static" "favicon.svg") -}}
<link rel="icon" type="image/svg+xml" href="{{ "favicon.svg" | relURL }}">
{{ end -}}
{{ if fileExists (path.Join "/static" "site.webmanifest") -}}
<link rel="manifest" href="{{ "site.webmanifest" | relURL }}">
{{ end -}}
{{ $favname := "" -}}
{{ $favsizes := slice "512x512" "256x256" "128x128" "96x96" "48x48" "32x32" "16x16" -}}
{{ range $favsizes -}}
{{ $favname = (printf "favicon-%s.png" .) -}}
{{ if fileExists (path.Join "/static" $favname) -}}
<link rel="icon" type="image/png" {{ printf "sizes=%q" . | safeHTMLAttr }} href="{{ $favname | relURL }}">
{{ end -}}
{{ end -}}

View file

@ -0,0 +1,11 @@
{{ $opts := dict "minify" true -}}
{{ if eq hugo.Environment "development" -}}
{{ $opts = merge $opts (dict "minify" false) -}}
{{ end -}}
{{ if or ($.Param "math") (.Page.Store.Get "math") (.HasShortcode "math") -}}
<link rel="stylesheet" href="{{ "katex/katex.min.css" | relURL }}">
<script defer src="{{ "katex/katex.min.js" | relURL }}"></script>
<script defer src="{{ "katex/contrib/auto-render.min.js" | relURL }}"></script>
{{ $math := resources.Get "js/math.js" | js.Build $opts | fingerprint -}}
<script defer src="{{ $math.RelPermalink }}"></script>
{{ end -}}

View file

@ -0,0 +1,29 @@
{{ $breadcrumbScratch := newScratch -}}
{{ $crumbScratch := newScratch -}}
{{ $crumbScratch.Set "itemListElement" (slice) -}}
{{ $breadPos := 0 -}}
{{ range .Ancestors.Reverse -}}
{{ $breadPos = (add $breadPos 1) -}}
{{ $crumbScratch.Add "itemListElement" (dict
"@type" "ListItem"
"position" $breadPos
"item" (dict
"@id" .Permalink
"name" .LinkTitle
)
) -}}
{{ end -}}
{{ $breadPos = (add $breadPos 1) -}}
{{ $crumbScratch.Add "itemListElement" (dict
"@type" "ListItem"
"position" $breadPos
"item" (dict
"@id" .Permalink
"name" .LinkTitle
)
) -}}
{{ $breadcrumbScratch.SetInMap "breadcrumb" "@context" "https://schema.org" -}}
{{ $breadcrumbScratch.SetInMap "breadcrumb" "@type" "BreadcrumbList" -}}
{{ $breadcrumbScratch.SetInMap "breadcrumb" "itemListElement" ($crumbScratch.Get "itemListElement") -}}
{{ $jsonifiedBreadcrumb := $breadcrumbScratch.Get "breadcrumb" | jsonify (dict "indent" " " "prefix" " ") -}}
{{ return ($jsonifiedBreadcrumb | safeJS) -}}

View file

@ -0,0 +1,60 @@
<script type="application/ld+json">
{{ $blogSections := site.Params.blogSections | default (slice "blog" "post") -}}
{{ $breadcrumbSections := site.Params.breadcrumbSections | default (slice) -}}
{
"@context": "https://schema.org",
{{ if .IsPage -}}
"@type": {{ if in $blogSections .Section }}"BlogPosting",{{ else }}"WebPage",
{{ if in $breadcrumbSections .Section -}}
"breadcrumb": {{ partial "head/meta-breadcrumb-json-ld.html" . }},
{{ end -}}
{{ end -}}
"headline": {{ .Title }},
"datePublished": {{ .Date.Format "2006-01-02T15:04:05Z07:00" }},
"dateModified": {{ .Lastmod.Format "2006-01-02T15:04:05Z07:00" }},
"url" : {{ .Permalink }},
{{ if .IsHome -}}
{{ with $.Param "description" }}"description": {{ . }},{{ end }}
{{ else -}}
{{ with .Description }}"description": {{ . }},{{ end }}
{{ end -}}
{{ with .Params.tags -}}
"keywords": {{ delimit . " " }},
{{ end -}}
{{ else -}}
"@type": "WebPage",
{{ if in $breadcrumbSections .Section -}}
"breadcrumb": {{ partial "head/meta-breadcrumb-json-ld.html" . }},
{{ end -}}
"url" : {{ .Permalink }},
"name": {{ .Title }},
{{ with $.Param "description" -}}
"description": {{ . }},
{{ end -}}
{{ end -}}
{{ with $.Param "image" -}}
"image" : {{ . | absURL }},
{{ end -}}
{{ with .Params.author | default site.Params.author.name -}}
"author": {
"@type": "Person",
"name": {{ . }}
},
{{ end -}}
"mainEntityOfPage": {
"@type": "WebPage",
"@id": {{ site.BaseURL }}
},
"publisher": {
"@type": "Organization",
"name": {{ site.Title }},
{{ with $.Param "icon" -}}
"logo" : {
"@type": "ImageObject",
"url": {{ . | absURL }}
},
{{ end -}}
"url": {{ site.BaseURL }}
}
}
</script>

View file

@ -0,0 +1,28 @@
{{ range .AlternativeOutputFormats -}}
<link rel="{{ .Rel }}" {{ printf "type=%q" .MediaType.Type | safeHTMLAttr }} title="{{ .Name }}" href="{{ .Permalink | safeURL }}">
{{ end -}}
{{ if .IsHome -}}
{{ with $.Param "description" }}<meta name="description" content="{{ . }}">{{ end }}
{{ else -}}
{{ with .Description }}<meta name="description" content="{{ . }}">{{ end }}
{{ end -}}
<meta name="created" {{ printf "content=%q" (.Date.Format "2006-01-02T15:04:05-0700") | safeHTMLAttr }}>
<meta name="modified" {{ printf "content=%q" (.Lastmod.Format "2006-01-02T15:04:05-0700") | safeHTMLAttr }}>
{{ with .Params.author | default site.Params.author.name }}<meta name="author" content="{{ . }}">{{ end }}
{{ with $.Param "contact" }}<meta name="contact" content="{{ . }}">{{ end }}
<meta property="og:site_name" content="{{ site.Title }}">
<meta property="og:title" content="{{ .Title }}">
<meta property="og:url" content="{{ .Permalink }}">
<meta property="og:type" content="{{ if .IsPage }}article{{ else }}website{{ end }}">
{{ with $.Param "image" }}<meta property="og:image" content="{{ . | absURL }}">{{ end }}
{{ hugo.Generator }}
<meta name="msapplication-TileColor" content="{{ $.Param "themecolor" | default "#ffffff" }}">
<meta name="theme-color" content="{{ $.Param "themecolor" | default "#ffffff" }}">
{{ with site.Params.piwikTrackerUrl }}<link rel="dns-prefetch" href="https://{{ . }}">{{ end }}
{{ with $.Param "microusername" }}<link rel="me" href="https://micro.blog/{{ . }}">{{ end }}
<link rel="canonical" href="{{ .Permalink }}">
{{ if .IsTranslated -}}
{{ range .Translations -}}
<link rel="alternate" hreflang="{{ .Site.Language.LanguageCode | default .Lang }}" href="{{ .Permalink }}">
{{ end -}}
{{ end -}}

View file

@ -0,0 +1,60 @@
{{ $opts := dict "minify" true -}}
{{ if eq hugo.Environment "development" -}}
{{ $opts = merge $opts (dict "minify" false) -}}
{{ end -}}
{{ $early := resources.Get "js/script-early.js" | js.Build $opts | fingerprint -}}
<script src="{{ $early.RelPermalink }}"></script>
{{ if $.Param "alpine" -}}
{{ $alpine := resources.Get "libs/alpine.min.js" | fingerprint -}}
<script defer src="{{ $alpine.RelPermalink }}"></script>
{{ end -}}
{{ if $.Param "jquery" -}}
{{ $jquery := resources.Get "libs/jquery.slim.min.js" | fingerprint -}}
<script defer src="{{ $jquery.RelPermalink }}"></script>
{{ end -}}
{{ if $.Param "umbrella" -}}
{{ $umbrella := resources.Get "libs/umbrella.min.js" | fingerprint -}}
<script defer src="{{ $umbrella.RelPermalink }}"></script>
{{ end -}}
{{ if $.Param "mobilemenu" -}}
{{ $mobilemenu := resources.Get "js/mobilemenu.js" | js.Build $opts | fingerprint -}}
<script defer src="{{ $mobilemenu.RelPermalink }}"></script>
{{ end -}}
{{ if $.Param "cookieconsent" -}}
{{ $cookieconsent := resources.Get "js/cookieconsent.js" | js.Build $opts | fingerprint -}}
<script defer src="{{ $cookieconsent.RelPermalink }}"></script>
{{ end -}}
{{ if $.Param "listsort" -}}
{{ $listmin := resources.Get "libs/list.min.js" | fingerprint -}}
<script defer src="{{ $listmin.RelPermalink }}"></script>
{{ $listsort := resources.Get "js/listsort.js" | fingerprint -}}
<script defer src="{{ $listsort.RelPermalink }}"></script>
{{ end -}}
{{ if $.Param "tables" -}}
{{ $tables := resources.Get "js/tables.js" | js.Build $opts | fingerprint -}}
<script defer src="{{ $tables.RelPermalink }}"></script>
{{ end -}}
{{ if .HasShortcode "contact" -}}
{{ $contact := resources.Get "js/contact.js" | js.Build $opts | fingerprint -}}
<script defer src="{{ $contact.RelPermalink }}"></script>
{{ end -}}
{{ if .HasShortcode "search" -}}
{{ $flexsearch := resources.Get "libs/flexsearch.compact.js" | fingerprint -}}
<script defer src="{{ $flexsearch.RelPermalink }}"></script>
{{ $search_opts := merge $opts (dict "params" (dict "searchLimit" (site.Params.searchLimit | default 20) "basePath" site.Home.RelPermalink)) -}}
{{ $search := resources.Get "js/search.js" | js.Build $search_opts | fingerprint -}}
<script defer src="{{ $search.RelPermalink }}"></script>
{{ end -}}
{{ $script := resources.Get "js/script.js" | js.Build $opts | fingerprint -}}
<script defer src="{{ $script.RelPermalink }}"></script>

View file

@ -0,0 +1,19 @@
{{ $main_options := (dict "targetPath" "css/styles.css" "outputStyle" "compressed" "enableSourceMap" false "transpiler" (site.Params.sassTranspiler | default "libsass")) -}}
{{ if eq hugo.Environment "development" -}}
{{ $main_options = merge $main_options (dict "outputStyle" "nested" "enableSourceMap" true) -}}
{{ end -}}
{{ $mobile_options := merge $main_options (dict "targetPath" "css/mobilemenu.css") -}}
{{ $print_options := merge $main_options (dict "targetPath" "css/print.css") -}}
{{ $main_style := resources.Get "sass/styles.scss" | toCSS $main_options -}}
{{ $mobile_style := resources.Get "sass/mobilemenu.scss" | toCSS $mobile_options -}}
{{ $print_style := resources.Get "sass/print.scss" | toCSS $print_options -}}
{{ if ne hugo.Environment "development" -}}
{{ $main_style = $main_style | fingerprint -}}
{{ $mobile_style = $mobile_style | fingerprint -}}
{{ $print_style = $print_style | fingerprint -}}
{{ end -}}
<link rel="stylesheet" href="{{ $main_style.RelPermalink }}">
{{ if $.Param "mobilemenu" -}}
<link rel="stylesheet" href="{{ $mobile_style.RelPermalink }}" media="screen">
{{ end -}}
<link rel="stylesheet" href="{{ $print_style.RelPermalink }}" media="print">

View file

@ -0,0 +1,26 @@
{{ $opts := dict
"minify" true
"params" (dict
"cookieConsent" site.Params.cookieConsent
"piwikTrackerUrl" site.Params.piwikTrackerUrl
"piwikSiteID" site.Params.piwikSiteID
"plausibleSiteID" site.Params.plausibleSiteID
"GoogleAnalytics" site.Config.Services.GoogleAnalytics.ID) -}}
{{ if eq hugo.Environment "development" -}}
{{ $opts = merge $opts (dict "minify" false) -}}
{{ end -}}
{{ if and site.Params.piwikTrackerUrl site.Params.piwikSiteID -}}
{{ $script := resources.Get "js/tracking.js" | js.Build $opts | fingerprint -}}
<script src="{{ $script.RelPermalink }}"></script>
<script defer src="https://{{ site.Params.piwikTrackerUrl }}/matomo.js"></script>
{{ end -}}
{{ if site.Params.plausibleSiteID -}}
<script async defer data-domain="{{ site.Params.plausibleSiteID }}" src="{{ site.Params.plausibleTrackerURL | default "https://plausible.io/js/plausible.js" }}"></script>
{{ end -}}
{{ if site.Config.Services.GoogleAnalytics.ID -}}
{{ $script := resources.Get "js/tracking.js" | js.Build $opts | fingerprint -}}
<script src="{{ $script.RelPermalink }}"></script>
{{ template "_internal/google_analytics.html" . }}
{{ end -}}

View file

@ -4,16 +4,14 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>{{ block "title" . }}{{ .Title }} – {{ site.Title }}{{ end }}</title>
{{ partial "meta.html" . }}
{{ partialCached "favicons.html" . }}
{{ partialCached "styles.html" . }}
{{ partial "meta-json-ld.html" . }}
{{ partial "scripts.html" . }}
{{ partial "math.html" . }}
{{ partialCached "tracking.html" . }}
{{ if templates.Exists "partials/head.html" -}}
{{ partial "head.html" . }}
{{ end -}}
{{ partial "head/meta.html" . }}
{{ partialCached "head/favicons.html" . }}
{{ partialCached "head/styles.html" . }}
{{ partial "head/meta-json-ld.html" . }}
{{ partial "head/scripts.html" . }}
{{ partial "head/math.html" . }}
{{ partialCached "head/tracking.html" . }}
{{ partial "head/extra.html" . }}
{{ block "head" . }}{{ end }}
</head>
@ -42,14 +40,7 @@
{{ if $.Param "sidebar" }}{{ partial "sidebar.html" . }}{{ end -}}
<footer class="footer layout__footer mt--l">
{{ if templates.Exists "partials/footer.html" -}}
{{ partial "footer.html" . }}
{{ else -}}
{{ if $.Param "feedlinks" }}{{ partial "feedlinks.html" . }}{{ end -}}
<p>{{ with site.Copyright }}{{ . | site.Home.RenderString }}{{ else }}<span>© {{ site.Title }}</span>{{ end }}</p>
{{ with $.Param "footer" }}<p>{{ . | site.Home.RenderString }}</p>{{ end }}
{{ if $.Param "poweredby" }}<p>Powered by <a href="https://gohugo.io/">Hugo</a> and the <a href="https://github.com/frjo/hugo-theme-zen">Zen theme</a>.</p>{{ end }}
{{ end -}}
</footer>
{{ if $.Param "cookieconsent" }}{{ partialCached "cookieconsent.html" . }}{{ end -}}