Conversation
Every page now gets a pageUrl derived from pageInfo.path so layouts can build canonical URLs without manually computing the path-to-URL conversion. User-supplied pageUrl in pageVars or globalVars still takes precedence. Closes #238
Coverage Report for CI Build 24619422519Coverage increased (+0.07%) to 91.537%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
There was a problem hiding this comment.
Pull request overview
This PR aims to make canonical URL construction easier in layouts by automatically injecting a pageUrl value into PageData.vars, derived from pageInfo.
Changes:
- Inject
pageUrlinto the base of thevarsmerge insidePageData.vars, allowing user-definedpageUrlto override it via later spreads.
Comments suppressed due to low confidence (1)
lib/build-pages/page-data.js:149
- New public-ish behavior (
vars.pageUrl) isn’t covered by tests. The repo already has node:test coverage for build behavior (eg test-cases/general-features/index.test.js). Please add a regression test that assertsvars.pageUrl(or an HTML marker rendered from it) for both an index page (/some-dir/) and a loose markdown page (/some-dir/file.html), and ideally cover Windows path normalization as well.
pageUrl: this.pageInfo.path ? `/${this.pageInfo.path}/` : '/',
...globalVars,
...globalDataVars,
...pageVars,
...builderVars,
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Loose markdown files (not page.md/README.md) have outputName set to their slug.html rather than index.html, so the previous formula produced an incorrect directory-style URL for them. The URL is now derived from outputName: index pages get a trailing slash, non-index pages include the filename. fsPathToUrlPath is used to normalize any OS-specific path separators.
There was a problem hiding this comment.
Pull request overview
This PR makes vars.pageUrl available to every rendered page by computing it from pageInfo inside PageData.vars, allowing layouts to build canonical/OG URLs without duplicating the project’s URL-construction convention.
Changes:
- Injects a computed
pageUrlintoPageData.varsat the base of the vars merge (so user overrides still win). - Computes
pageUrlwith special handling forindex.html(trailing-slash URLs) vs non-index outputs (include filename). - Normalizes URL paths via
fsPathToUrlPath()for cross-platform (Windows) safety.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Adds automatic vars.pageUrl injection to every page so layouts can build canonical URLs without manually reconstructing URL path conventions.
Changes:
- Inject
pageUrlintoPageData.varsat the lowest precedence so user-defined vars can override it. - Compute
pageUrlbased onpageInfo.path+outputName, mappingindex.htmlto trailing-slash URLs and including filenames for non-index outputs. - Normalize path separators via
fsPathToUrlPath()for cross-platform URL consistency.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ules Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Every page now receives a
pageUrlvariable derived from its output location, so layouts can construct canonical URLs without manually computing the path convention.The URL is computed based on the page's
outputName:outputName === 'index.html'): get a trailing-slash URL, e.g./blog/my-post/, or/for the root.loose-md.html): get a URL that includes the filename, e.g./md-page/loose-md.html.This means
pageUrldoes not always end with a trailing slash — layouts that need to link to loose markdown pages will get the full path including the filename.The value is injected at the base of the vars merge, so user-supplied
pageUrlinpage.vars.jsorglobal.vars.jsstill takes precedence.fsPathToUrlPathis used to normalize path separators for cross-platform safety.Closes #238