diff options
| author | Nicholas Johnson <> | 2026-09-20 00:00:00 +0000 |
|---|---|---|
| committer | Nicholas Johnson <> | 2026-09-20 00:00:00 +0000 |
| commit | 93831052e8ba9537d47474e1f8dbf04d9eceb9b0dff214ce422fcafe1ffaecac (patch) | |
| tree | c774c1eed616eccd64e1a26fc8dac3589e7875487009b274b3f319ac54a11948 /layouts/_partials/pageinfo.html | |
| parent | 98be685a6f839234a0ebc07c9cba001c21c5786957d3b1d627535cfa7a56c032 (diff) | |
| download | hugo-theme-journal-93831052e8ba9537d47474e1f8dbf04d9eceb9b0dff214ce422fcafe1ffaecac.tar.gz hugo-theme-journal-93831052e8ba9537d47474e1f8dbf04d9eceb9b0dff214ce422fcafe1ffaecac.zip | |
Drop whitespace trimming from HTML and XML templates
Whitespace has no effect on the HTML and Atom output, so the trim
markers on nearly every action in those templates bought nothing and
made them harder to read and to edit: a maintainer had to carry the
markers along with the change. The markers are load-bearing in the
gemtext templates alone, where output whitespace is the formatting.
Remove them from the HTML and Atom templates. The audio partial keeps
its markers, since the gemtext single template uses it too. The two
markup render hooks keep theirs as well, because their output is
spliced inline into prose, where the newlines an untrimmed hook emits
render as a space before the punctuation that follows a link.
The Atom templates compute their author and entry variables before
emitting anything, so untrimmed they put blank lines ahead of the XML
declaration and left every feed malformed. Emit the declaration first
instead; whitespace is allowed after it but not before it.
The example site builds byte-identical gemtext and content-identical
feeds, and its HTML differs only by a space after a "p" start tag that
the whitespace processing model drops.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Diffstat (limited to 'layouts/_partials/pageinfo.html')
| -rw-r--r-- | layouts/_partials/pageinfo.html | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/layouts/_partials/pageinfo.html b/layouts/_partials/pageinfo.html index 47f1194..b9a8d63 100644 --- a/layouts/_partials/pageinfo.html +++ b/layouts/_partials/pageinfo.html @@ -1,28 +1,28 @@ -{{ $dateFormat := .Site.Params.dateFormat | default ":date_long" -}} +{{ $dateFormat := .Site.Params.dateFormat | default ":date_long" }} -{{/* user-overridable parameter $dateFormat is escaped pre-insertion so that HTML entities can be inserted */ -}} -{{ $nonBreakingPublishDate := .Page.PublishDate | time.Format $dateFormat | htmlEscape -}} -{{ $nonBreakingPublishDate = replace $nonBreakingPublishDate " " " " -}} -{{ $nonBreakingPublishDate = replace $nonBreakingPublishDate "-" "‑" -}} +{{/* user-overridable parameter $dateFormat is escaped pre-insertion so that HTML entities can be inserted */}} +{{ $nonBreakingPublishDate := .Page.PublishDate | time.Format $dateFormat | htmlEscape }} +{{ $nonBreakingPublishDate = replace $nonBreakingPublishDate " " " " }} +{{ $nonBreakingPublishDate = replace $nonBreakingPublishDate "-" "‑" }} -{{/* user-overridable parameter $readingTime is escaped pre-insertion so that HTML entities can be inserted */ -}} -{{ $nonBreakingReadingTime := i18n "readingTime" .ReadingTime | htmlEscape -}} -{{ $nonBreakingReadingTime = replace $nonBreakingReadingTime " " " " -}} -{{ $nonBreakingReadingTime = replace $nonBreakingReadingTime "-" "‑" -}} +{{/* user-overridable parameter $readingTime is escaped pre-insertion so that HTML entities can be inserted */}} +{{ $nonBreakingReadingTime := i18n "readingTime" .ReadingTime | htmlEscape }} +{{ $nonBreakingReadingTime = replace $nonBreakingReadingTime " " " " }} +{{ $nonBreakingReadingTime = replace $nonBreakingReadingTime "-" "‑" }} -{{ $breakingTags := .Param (lower (i18n "tags")) -}} -{{ $nonBreakingTags := slice -}} -{{ range $breakingTags -}} - {{/* user-defined tags are escaped pre-insertion so that HTML entities can be inserted */ -}} - {{ $nonBreakingTag := htmlEscape . -}} - {{ $nonBreakingTag = replace $nonBreakingTag " " " " -}} - {{ $nonBreakingTag = replace $nonBreakingTag "-" "‑" -}} - {{ $nonBreakingTags = $nonBreakingTags | append $nonBreakingTag -}} -{{ end -}} +{{ $breakingTags := .Param (lower (i18n "tags")) }} +{{ $nonBreakingTags := slice }} +{{ range $breakingTags }} + {{/* user-defined tags are escaped pre-insertion so that HTML entities can be inserted */}} + {{ $nonBreakingTag := htmlEscape . }} + {{ $nonBreakingTag = replace $nonBreakingTag " " " " }} + {{ $nonBreakingTag = replace $nonBreakingTag "-" "‑" }} + {{ $nonBreakingTags = $nonBreakingTags | append $nonBreakingTag }} +{{ end }} -{{/* user-overridable parameter $audioAvailable is escaped pre-insertion so that HTML entities can be inserted */ -}} -{{ $nonBreakingAudioAvailable := i18n "audioAvailable" .Title | htmlEscape -}} -{{ $nonBreakingAudioAvailable = replace $nonBreakingAudioAvailable " " " " -}} -{{ $nonBreakingAudioAvailable = replace $nonBreakingAudioAvailable "-" "‑" -}} +{{/* user-overridable parameter $audioAvailable is escaped pre-insertion so that HTML entities can be inserted */}} +{{ $nonBreakingAudioAvailable := i18n "audioAvailable" .Title | htmlEscape }} +{{ $nonBreakingAudioAvailable = replace $nonBreakingAudioAvailable " " " " }} +{{ $nonBreakingAudioAvailable = replace $nonBreakingAudioAvailable "-" "‑" }} <span class="meta-item">{{ emojify ":calendar:" }} <time {{ printf "datetime=%q" (.Page.PublishDate | time.Format "2006-01-02T15:04:05-0700") | safeHTMLAttr }}>{{ $nonBreakingPublishDate | safeHTML }}</time></span><span class="meta-item">{{ emojify ":stopwatch:" }} <time datetime="PT{{ .ReadingTime }}M">{{ $nonBreakingReadingTime | safeHTML }}</time></span>{{ if where .Resources "MediaType.MainType" "audio" }}<span class="meta-item">{{ emojify ":headphones:" }} {{ $nonBreakingAudioAvailable | safeHTML }}</span>{{ end }}{{ if $nonBreakingTags }}<span class="meta-item">{{ emojify ":label:" }} {{ range $key, $val := $nonBreakingTags }}{{ if $key }} {{ end }}<a class="link link--internal" href='{{ relLangURL (lower (i18n "tags")) }}/{{ index $breakingTags $key | urlize }}/' rel="noreferrer">{{ $val | safeHTML }}</a>{{ end }}</span>{{ end }} |
