From d4ae7d9c03015778cdacbcbde52041b9dcbad7d92497529e9d460ddf42dcdb50 Mon Sep 17 00:00:00 2001 From: Nicholas Johnson <> Date: Fri, 18 Sep 2026 00:00:00 +0000 Subject: Handle missing optional site files gracefully Two site files the theme reads were assumed to exist. A site without templates/logo.txt got an empty preformatted block at the top of every page in both output formats, styled with the logo's margins, rather than no logo at all. A typo in params.custom_css produced a nil pointer error naming only the template line, since the result of resources.Get was used without checking it. Skip the header entirely when there is no logo, and report a missing stylesheet by name. Co-Authored-By: Claude Opus 5 --- layouts/_partials/head.html | 12 ++++++------ layouts/_partials/header.gmi | 4 +++- layouts/_partials/header.html | 4 +++- layouts/baseof.gmi | 3 ++- 4 files changed, 14 insertions(+), 9 deletions(-) (limited to 'layouts') diff --git a/layouts/_partials/head.html b/layouts/_partials/head.html index 5a1f89a..0c5a796 100644 --- a/layouts/_partials/head.html +++ b/layouts/_partials/head.html @@ -8,12 +8,12 @@ {{ if $.Site.Params.keywords }} {{- end -}} - {{ if .Site.Params.custom_css -}} - {{ range .Site.Params.custom_css }} - - {{- end -}} - {{ else }} - + {{ range .Site.Params.custom_css | default (slice "static/css/style.css") }} + {{- with resources.Get . }} + + {{- else }} + {{- errorf "stylesheet %q listed in params.custom_css was not found in the assets directory" . }} + {{- end }} {{- end -}} {{ with .OutputFormats.Get "Atom" }} diff --git a/layouts/_partials/header.gmi b/layouts/_partials/header.gmi index c70f84a..972a82b 100644 --- a/layouts/_partials/header.gmi +++ b/layouts/_partials/header.gmi @@ -1,3 +1,5 @@ +{{ if fileExists "templates/logo.txt" -}} ```plaintext {{ chomp (readFile "templates/logo.txt") }} -``` \ No newline at end of file +``` +{{- end -}} diff --git a/layouts/_partials/header.html b/layouts/_partials/header.html index d8ec881..0c2d87e 100644 --- a/layouts/_partials/header.html +++ b/layouts/_partials/header.html @@ -1,5 +1,7 @@ +{{ if fileExists "templates/logo.txt" -}} \ No newline at end of file + +{{- end -}} diff --git a/layouts/baseof.gmi b/layouts/baseof.gmi index 09cdbac..afb7941 100644 --- a/layouts/baseof.gmi +++ b/layouts/baseof.gmi @@ -1,6 +1,7 @@ -{{ partial "header.gmi" . }} +{{ with partial "header.gmi" . }}{{ . }} +{{ end -}} {{ block "main" . }}{{ end }} -- cgit v1.2.3