Skip to content

Pass global.data.js output to template vars#240

Open
bcomnes wants to merge 5 commits intomasterfrom
fix/template-global-data-vars
Open

Pass global.data.js output to template vars#240
bcomnes wants to merge 5 commits intomasterfrom
fix/template-global-data-vars

Conversation

@bcomnes
Copy link
Copy Markdown
Owner

@bcomnes bcomnes commented Apr 18, 2026

Closes #235

Templates received only global.vars.js output in vars, while pages received both global.vars.js and global.data.js output via the PageData.vars getter. This inconsistency forced every template that needed aggregated data to re-derive it from the pages array, duplicating logic that global.data.js already performs.

The fix merges globalDataVars into the globalVars object passed to templateBuilder, making template vars consistent with how page vars already work.

Before this change, a feeds template that needed aggregated post data had to re-implement the full filtering and sorting pipeline from global.data.js. After this change it can read vars.recentPosts (or whatever global.data.js returns) directly.

The merge order follows the same precedence as PageData.vars: globalVars is the base, and globalDataVars overrides it. Templates that do not have a global.data.js file are unaffected since globalDataVars will be an empty object in that case.

Templates received only global.vars.js output in vars, while pages
received both global.vars.js and global.data.js output via PageData.vars.
This inconsistency forced every template that needed aggregated data to
re-derive it from the pages array, duplicating logic from global.data.js.

Merging globalDataVars into the globalVars object passed to templateBuilder
makes template vars consistent with how page vars already work.
Copilot AI review requested due to automatic review settings April 18, 2026 17:53
@coveralls
Copy link
Copy Markdown

coveralls commented Apr 18, 2026

Coverage Report for CI Build 24619419220

Coverage increased (+0.009%) to 91.478%

Details

  • Coverage increased (+0.009%) from the base build.
  • Patch coverage: 14 of 14 lines across 4 files are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 4075
Covered Lines: 3809
Line Coverage: 93.47%
Relevant Branches: 642
Covered Branches: 506
Branch Coverage: 78.82%
Branches in Coverage %: Yes
Coverage Strength: 73.56 hits per line

💛 - Coveralls

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Aligns template rendering with page rendering by ensuring templates receive global.data.js outputs in vars, eliminating duplicated aggregation logic in templates and resolving the inconsistency described in #235.

Changes:

  • Merge globalDataVars into the globalVars object passed to templateBuilder, with globalDataVars taking precedence.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/build-pages/index.js Outdated
Comment thread lib/build-pages/index.js Outdated
Comment thread lib/build-pages/index.js
Merges globalVars and globalDataVars once before the pMap loop instead
of once per template render. Updates TemplateFunction and templateBuilder
JSDoc to accurately describe that vars now includes global.data.js output.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR makes template rendering receive the same aggregated site variables as pages by merging global.data.js output into the vars passed to templates, aligning template behavior with PageData.vars.

Changes:

  • Hoists a single merged templateGlobalVars = { ...globalVars, ...globalDataVars } and passes it into templateBuilder() for all template renders.
  • Updates template builder JSDoc to reflect that template vars includes global.data.js output.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
lib/build-pages/index.js Merges globalVars + globalDataVars once per build and passes merged vars into templateBuilder()
lib/build-pages/page-builders/template-builder.js Updates JSDoc to document the expanded vars contract for templates

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/build-pages/page-builders/template-builder.js Outdated
bcomnes and others added 2 commits April 18, 2026 12:52
global.data.js now returns a globalDataSentinel value. feeds.template.js reads
it from vars and includes it as a custom extension field in feed.json. The test
asserts the sentinel appears in the generated feed, which only passes when
globalDataVars are correctly merged into templateGlobalVars.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR makes template rendering consistent with page rendering by including global.data.js output in the vars object passed to templates, eliminating the need for templates to re-derive aggregated site data from pages.

Changes:

  • Merge globalDataVars into the globalVars passed to templateBuilder() (with global.data.js taking precedence).
  • Update templateBuilder/template function JSDoc to reflect the expanded vars contract.
  • Add an integration regression test ensuring global.data.js output is visible in template vars.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test-cases/general-features/src/global.data.js Adds a sentinel value to verify global.data.js output can flow into template vars.
test-cases/general-features/src/feeds.template.js Reads the sentinel from vars and emits it into feed.json for verification.
test-cases/general-features/index.test.js Asserts the generated feed includes the sentinel value, covering the new behavior end-to-end.
lib/build-pages/page-builders/template-builder.js Updates JSDoc to describe vars as global.vars merged with global.data output.
lib/build-pages/index.js Hoists and passes a merged {...globalVars, ...globalDataVars} object into templateBuilder().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/build-pages/index.js Outdated
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Owner Author

@bcomnes bcomnes left a comment

Choose a reason for hiding this comment

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

This looks good. Just make sure it's done consistently with how pages handles this

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.

Templates should receive global.data.js output in vars, not just global.vars.js

3 participants