Define effective page type once (currently three byte-for-byte mirrors) #115
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Cloonar/deckle#115
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Found by an architecture review (deepening opportunities — turning shallow modules into deep ones).
Files:
internal/pageops/pagetypes.go(effectiveTypeOf/impliedType),internal/pagetree/build.go:384-413(comments: "mirrors pageops.effectiveTypeOf", "mirrors pageops.impliedType byte for byte"), plus the frontend mirroreffectiveNodeType.Problem: Hugo's explicit-front-matter-
type-else-section-name-fallback rule exists three times becausepageopsimportspagetreeand not the reverse — an import cycle fossilized as duplication the comments openly apologize for.pageops.EffectiveTypeis itself a one-line pass-through wrapper existing only to export the private function toserver.Solution: move the rule into a module both Go packages can import (
pagetreeitself, or a tiny leaf package). The frontend copy stays (it cannot import Go) but gets a conformance test against shared fixtures.Benefits: Locality — a change to type resolution (new page-type feature, Hugo behaviour change) is one edit, not three synchronized ones. Small, low-risk, high-confidence extraction.
Agent Brief
Category: enhancement
Summary: Define Hugo's effective-page-type rule once in a new tiny leaf Go package; delete the two duplicated Go implementations; conformance-test the frontend mirror against shared fixtures.
Current behavior:
The rule "a page's effective type is its explicit front-matter
typewhen non-empty, else Hugo's section-name fallback" is implemented three times:internal/pageops— privateeffectiveTypeOf(reads the page file's front matter itself) plusimpliedType; the exportedpageops.EffectiveType(root, page string) stringis a one-line pass-through that the HTTP server layer calls.internal/pagetree— privateeffectiveType(pagePath, explicitType string)(pure — the tree builder already has the parsed front matter) plus its ownimpliedType, whose comments admit "mirrors pageops.impliedType byte for byte; kept local because pageops imports pagetree, not the reverse".effectiveNodeType/impliedPageTypein the page-management module, unit-tested but with no link guaranteeing it matches the Go rule.The fallback semantics all three encode: the page's top-level section name —
posts/first.md→posts,posts/_index.md→posts; a leaf bundle's own directory does not count (posts/foo/index.md→posts,foo/index.mdat the root →""); root-level pages (including the content root_index.md) →"".Desired behavior:
pagetree) owns the pure rule: an implied-type function of the page path, and an effective-type function of (path, explicit type). It should depend on the standard library only, so anything may import it. Pick a short descriptive name (e.g. something likepagepath); document the semantics above, including the leaf-bundle and content-root cases.internal/pageopsandinternal/pagetreeboth delegate to it; their private duplicates and the "mirrors … byte for byte" apology comments disappear.pageopskeeps only its thin file-reading wrapper (read front matter, take explicittypeif non-empty string, else fall back), andpageops.EffectiveTypekeeps its exported signature and behavior — the server call sites should not need changes._index.mdsection page, leaf bundle in a section, leaf bundle at root, root-level page, content-root_index.md.Key interfaces:
pageops.EffectiveType(root, page string) string— must remain exported with identical behavior (HTTP layer depends on it).internal/pagetypedeliberately does NOT compute this fallback (its package doc says so) — do not move the rule there or change that boundary.Acceptance criteria:
pageopsorpagetree.go test ./...and the web test suite pass with no behavior change.Out of scope:
internal/pagetype's no-resolution boundary.scaffold/site/AGENTS.md— nothing it documents changes here.