There are several conditions that can produce errors in your published site which are not detected during the build. Run this audit before your final build. Yes, I understand that this means building the site twice.
HUGO_MINIFY_TDEWOLFF_HTML_KEEPCOMMENTS=true HUGO_ENABLEMISSINGTRANSLATIONPLACEHOLDERS=true hugo && grep -inorE "<\!-- raw HTML omitted -->|ZgotmplZ|\[i18n\]|\(<nil>\)|(<nil>)|hahahugo" public/
Tested with GNU Bash 5.0 / GNU grep 3.4.
- Retain HTML comments even if minification is enabled. This takes precedence over
[minify.tdewolff.html.keepComments]in the site configuration. If you minify without keeping HTML comments when performing this audit, you will not be able to detect when raw HTML has been omitted.
- Show a placeholder instead of the default value or an empty string if a translation is missing. This takes precedence over
enableMissingTranslationPlaceholdersin the site configuration.
- Ignore case distinctions in patterns and input data, so that characters that differ only in case match each other.
- Prefix each line of output with the 1-based line number within its input file.
- Print only the matched (non-empty) parts of a matching line, with each such part on a separate output line.
- Read all files under each directory, recursively, following symbolic links only if they are on the command line.
- Interpret PATTERNS as extended regular expressions.
<!-- raw HTML omitted -->
- By default, Hugo strips raw HTML from your markdown prior to rendering, and leaves this HTML comment in its place.
- ZgotmplZ is a special value that indicates that unsafe content reached a CSS or URL context at runtime. For more information see https://pkg.go.dev/html/template.
- This is the placeholder produced instead of the default value or an empty string if a translation is missing.
- This string will appear in the rendered HTML when passing a nil value to the
- Same as above when the value returned from the
printffunction has not been passed through
- Under conditions too complex to explain in this article, a rendered shortcode may include all or a portion of the string
HAHAHUGOSHORTCODEin either uppercase or lowercase. This is difficult to detect in all circumstances because, depending on a variety of factors, the rendered shortcode may include
HAHAHUGO, etc. A case-insensitive search of the output for
HAHAHUGOis likely to catch the majority of cases without producing false positives.
The problems that this audit detects are surprisingly common in public sites created with Hugo. While you would have to view source in your browser to detect
<!-- raw HTML omitted ‐‐> or
ZgotmplZ, you can easily find instances of
HAHAHUGOSHORTCODE with a simple search.