hugo: fail the build on broken include references

The include shortcode previously called readFile directly, which renders
nothing when the target is missing instead of failing. That let renamed
or deleted snippets linger as silent no-ops (for example the stale
scout-early-access.md and compose/develop.md references).

Check fileExists first and errorf with the shortcode position when the
target is missing, mirroring the file/files shortcodes. Verified against
Hugo 0.163.0: valid includes still render; a missing target now fails the
build with the offending file and line.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
David KarlssonandClaude Opus 4.8 committed 2026-06-18 11:08:24 +02:00
1 parent f62d925a50
commit 482519b7d1
1 file changed
+15 -1
+15 -1
View File
@@ -1,3 +1,17 @@
{{/*
include shortcode — inlines a reusable snippet from content/includes.
Usage:
{{% include "root-errors.md" %}}
{{% include "compose/services.md" %}}
The argument is a path relative to content/includes. The build fails with
a clear message if the target does not exist, so a renamed or deleted
snippet surfaces immediately instead of silently rendering nothing.
*/}}
{{ $fileToInclude := .Get 0 }}
{{ $filePath := printf "includes/%s" $fileToInclude }}
{{ readFile $filePath | safeHTML }}
{{ if not (fileExists $filePath) }}
{{- errorf "include shortcode: file %q not found: %s" $filePath .Position -}}
{{ end }}
{{ readFile $filePath | safeHTML }}