-
Notifications
You must be signed in to change notification settings - Fork 69
Description
Summary
Add a mechanism for the liquid engine to report warnings (non-fatal issues) alongside rendered output. This enables callers to detect and report problematic template patterns without failing the build.
Motivation
The immediate use case is dot-notation in assign tags ({% assign page.canonical_url = page.url %}). Ruby Jekyll/Liquid accepts this syntax without error, but it's effectively a no-op — the value is stored under the literal key "page.canonical_url" in assigns, but {{ page.canonical_url }} resolves by looking up page then .canonical_url on the page drop, so the assigned value is never accessible.
Currently, the liquid engine either:
- Errors on this syntax (when
JekyllExtensionsis disabled) — breaking compatibility with Jekyll sites that use it - Silently accepts it (when
JekyllExtensionsis enabled) — hiding broken code
Neither is ideal. A warnings mechanism would let callers accept the syntax for compatibility while informing users their code doesn't do what they expect.
Proposed approach
Add a ParseAndRenderDetailed method (or similar) that returns a result struct including warnings:
type RenderResult struct {
Output []byte
Warnings []Warning
}
type Warning struct {
Loc SourceLoc
Message string
}The existing ParseAndRender signature stays unchanged (discards warnings) for backward compatibility.
For the dot-notation assign case specifically:
- When
JekyllExtensionsis disabled: treat as a warning (not an error), execute as a no-op - The warning message should explain that the syntax has no effect, e.g.: "{% assign page.custom_var = ... %} has no effect. Dot notation in assign creates an inaccessible variable."
Why return values rather than a callback
- Fits naturally with callers that collect results before reporting (e.g., gojekyll collects errors across all pages before reporting)
- Enables strict mode: render first, then check
if len(warnings) > 0 && strict { return error } - Cleaner API — pure data in, data out, no threading concerns
- No breaking changes to existing API
Related
- Feature request: object attribute assign gojekyll#60 — original feature request for dot-notation assign
- feat: enable Jekyll-compatible dot notation in assign tags gojekyll#120 — PR that enables
EnableJekyllExtensions()(to be superseded by this approach)