Skip to content

Trim blank lines from the rendered <head> - #697

Merged
compscidr merged 2 commits into
mainfrom
compscidr/nit-code-gap
Oct 21, 2026
Merged

compscidr merged 2 commits into
mainfrom
compscidr/nit-code-gap

Conversation

@compscidr

Copy link
Copy Markdown
Collaborator

Fixes #649.

Actions in templates/shared/_head.html that print nothing (variable assignments, false ifs) left their line's newline + indent behind, so view-source showed a run of empty lines between the robots meta and <title> (and smaller gaps further down, including inside the JSON-LD).

  • Line-leading actions now use {{- to trim the whitespace before them.
  • One-line conditional tags ({{ if X }}<meta>{{ end }}) are split so the branch carries its own newline.
  • {{ define "_head" -}} so <!DOCTYPE html> is the first byte.
  • TestHeadMetadata now asserts the rendered head has no blank lines on home, post, plugin and search pages.

Note: main currently fails to build tests due to stale goblog/ imports, and TestPostTypeListing / TestPageAndPostTypeAPI_NonAdmin panic on commaList not defined — both pre-existing on main and unrelated to this change. I verified locally with the imports rewritten temporarily.

🤖 Generated with Claude Code

Template actions that print nothing (assignments, false ifs) left their
line's newline and indent behind, so view-source showed a run of empty
lines between the robots meta and <title>. Line-leading actions now trim
the whitespace before them and conditional tags carry their own newline.

Fixes #649

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 17, 2026 09:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The whitespace-only template change is consistent and correct across every branch (verified by standalone rendering), and it is covered by a new assertion with no behavioral or structural regressions.

No open issues 🎉

What changed in this PR

This PR fixes issue #649, where view-source of a rendered page showed runs of empty lines in the <head> — most visibly between the robots meta and <title>, plus smaller gaps (including inside the JSON-LD). The root cause was that template actions that emit nothing (variable assignments, false ifs) still left behind their line's newline + indentation. The fix applies Go template whitespace trimming ({{-) to line-leading actions and splits one-line conditional tags so the emitted markup carries its own newline, keeping templates/shared/_head.html the authoritative place that assembles every page's head.

Changes:

  • Prefix line-leading, no-output actions with {{- to trim the preceding whitespace, and split inline conditional tags ({{ if X }}<meta>{{ end }}) so the branch body is on its own line.
  • Make {{ define "_head" -}} so <!DOCTYPE html> is the first byte of output.
  • Extend TestHeadMetadata to assert the rendered head contains no blank lines on home, post, plugin, and search pages.
File Description
templates/​shared/​_head.html Adds {{- trims and splits inline conditionals so empty-output actions no longer leave blank lines; trims the define body so output starts at <!DOCTYPE html>.
blog/​blog_test.go Adds a loop in TestHeadMetadata asserting the rendered head has no blank lines across home, post, plugin, and search pages.

I manually traced the whitespace semantics through the changed branches and also rendered the template standalone across all paths (home, post, plugin, search, admin, login, the full site_is_person Person block with populated and empty optionals, and custom_header_code/plugin_head_html). Every branch produced no blank lines, and the Person JSON-LD remained structurally valid. The new test's regexp dependency is already imported and the head/get/check helpers are in scope.

Review effort: Balanced

@compscidr
compscidr merged commit 1b5ae03 into main Oct 21, 2026
5 checks passed
@compscidr
compscidr deleted the compscidr/nit-code-gap branch October 21, 2026 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nit: code gap

2 participants