fix(templates): stop leaking the template's title into published pages#217
Open
hrq-chiuchi wants to merge 1 commit into
Open
fix(templates): stop leaking the template's title into published pages#217hrq-chiuchi wants to merge 1 commit into
hrq-chiuchi wants to merge 1 commit into
Conversation
composeTemplateChain always returned the innermost TEMPLATE's title as the merged page's title, never the actual page or entry being rendered. Every published page's <title> and <head> metadata came from whichever template wrapped it: ordinary pages all showed the "everywhere" template's title, and post-type entries showed the postType template's title instead of the entry's own title. For a page terminal, terminal.page is already available inside composeTemplateChain, so use its title directly. For an entry terminal there is no Page object at that layer, so the two callers (renderPublishedDataRowTemplate and the row preview handler) set merged.title from the published/draft row's own title cell right after composing, before the page is rendered.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
composeTemplateChain(src/core/templates/templateCompose.ts) always returnedtitle: innermost.title— the title of the innermost template in the chain, never the title of the actual page or entry being rendered.<title>and derived<head>metadata came from whichever template wrapped it.<title>as the site's "everywhere" template's own title (e.g. "Site Template" for every single page).<title>as the postType template's title (e.g. every blog post showed "Post Template", every event showed "Event Template") instead of the entry's own title.<title>across/,/about, an entry page, and its listing page after publish.Fix
pageterminal,terminal.pageis already passed intocomposeTemplateChain— use itstitleinstead of the template's.entryterminal there's noPageobject at that layer (the entry's body flows in viadynamicBindings, not a splicedPage), so the two callers that resolve entry routes (renderPublishedDataRowTemplateinserver/publish/publicRenderer.ts, and the row preview handler inserver/handlers/cms/data/preview.ts) now setmerged.titlefrom the row's owntitlecell immediately after composing, before the page is rendered — following the sametypeof cells.title === 'string'pattern already used insrc/core/data/pageFromRow.ts.Test plan
bunx tsc -b --noEmitpassesbun testpasses, includingsrc/core/templates/__tests__/templateCompose.test.ts<title>now matches the actual page/entry title rather than the wrapping template's title