Skip to content

Add generated pages files - #253

Open
bcomnes wants to merge 1 commit into
masterfrom
docs/redirect-template-pattern
Open

Add generated pages files#253
bcomnes wants to merge 1 commit into
masterfrom
docs/redirect-template-pattern

Conversation

@bcomnes

@bcomnes bcomnes commented Apr 18, 2026

Copy link
Copy Markdown
Owner

Summary

  • add *.pages.{js,mjs,cjs,ts,mts,cts} files for generating one or more pages programmatically
  • pass initialized concrete pages, global vars, pages-file metadata, and site data into generated-page functions
  • run generated pages through the normal vars/layout pipeline and expose them to global data and templates
  • validate output paths and definitions, detect output conflicts, and rebuild generated pages when watched page inputs change
  • document generated pages with redirect and programmatic index examples

Validation

  • npm run test:node-test
  • npm run test:neostandard
  • npm run test:tsc currently reaches two pre-existing unused @ts-expect-error directives in lib/build-pages/page-builders/md/get-md.js

Closes #237

@coveralls

coveralls commented Apr 18, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 30656524054

Coverage increased (+0.4%) to 92.467%

Details

  • Coverage increased (+0.4%) from the base build.
  • Patch coverage: 27 uncovered changes across 3 files (484 of 511 lines covered, 94.72%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
index.js 55 38 69.09%
lib/build-pages/index.js 256 248 96.88%
lib/helpers/domstack-error.js 33 31 93.94%
Total (15 files) 511 484 94.72%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 4790
Covered Lines: 4545
Line Coverage: 94.89%
Relevant Branches: 799
Covered Branches: 623
Branch Coverage: 77.97%
Branches in Coverage %: Yes
Coverage Strength: 76.3 hits per line

💛 - Coveralls

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds documentation for an idiomatic DomStack pattern to generate redirect artifacts via templates, aimed at helping users migrate URLs without built-in redirect support.

Changes:

  • Adds a “Redirect Pages” documentation section with an object-array template example that generates meta-refresh HTML redirect pages.
  • Adds a second example showing how to generate a Netlify/Cloudflare Pages _redirects file via a template.
  • Includes an inline escaping helper and brief SEO guidance.

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

Comment thread README.md Outdated
Comment thread README.md Outdated
Comment thread README.md Outdated
Comment thread README.md Outdated
@bcomnes

bcomnes commented Apr 18, 2026

Copy link
Copy Markdown
Owner Author

Addressed all four review comments:

  1. Single string return wording (comment 3105658491): The Netlify example uses the single-object template type (returns { outputName, content }), not a plain string. Updated to "single-object template type".

  2. escapeXml XSS claim (comment 3105658495): Narrowed the prose to say escapeXml prevents HTML injection in attribute values. Added a note that it does not block javascript: scheme URLs, and to keep redirect targets to known-safe URL patterns.

  3. Section placement (comment 3105658504): Moved the Redirect Pages section from under TypeScript Support to the correct location at the end of the Templates section (after the RSS Feed example, before Global Assets).

  4. Leading / in outputName (comment 3105658508): Added a warning that outputName is resolved with path.resolve, so a leading / in from values would write outside the build directory.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

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


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

Comment thread README.md Outdated
Comment thread README.md Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

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


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

Comment thread README.md Outdated
@bcomnes

bcomnes commented Apr 20, 2026

Copy link
Copy Markdown
Owner Author

Ok so this doesn't actually close the upstream issue. But it is a decent docs addition.

In terms of docs, I would suggest simplifying the example and pull in fragtml or common-tags or something for html escaping. I would also leave out the copy directory example. Of course it works but that whole feature is just an escape hatch.
Another solution is to just make a regular page or layout and add the redirect header, keeping with the literal site layout.

We should implement the feature though but I'm not sold on the best approach.

@bcomnes

bcomnes commented Jun 25, 2026

Copy link
Copy Markdown
Owner Author

I thought about this some more.

Redirect pages are just pages, so if you want a redirect page pattern, you should implement a redirect template, and then just place a page where you want the redirect and then feed in the target as front matter or a page var.

Simple!

Ok but you have a lot of redirects you want to manage in one place? Fine! We need a new feature here.

Template files let you write out any kind of file type, but require that you define the output content.

What if we extend the template file type to allow you to specify a layout and any other variables, including children and whatnot that pages get.

Alternatively we implement something similar to template files, for pages specifically.

It would let you define multiple page outputs and templates as well as the page variables going into them in a single file. What would these be called?

This approach keeps the layout system and variable system in play, but also offers a way to centrally spit out multiple pages. If done right (maybe like after the main page walk), you could programmatically generate index pages for blogs and whatnot.

@bcomnes

bcomnes commented Jun 25, 2026

Copy link
Copy Markdown
Owner Author

Given the close overlap with pages, I think a separate whatever-you-want.pages.ts type might be warranted here.

Page walk, pass in the static structure into the pages files (allowing reflection/introspection) then build these *.pages.ts pages out, then continue on with the post vars rendering. Check for page conflicts.

This way .pages files can look for all blog/202* directories and place index files automatically for you.

You can also statically specify a central redirect list using whatever redirect template you want.

@bcomnes
bcomnes force-pushed the docs/redirect-template-pattern branch 3 times, most recently from 098588c to c9bb5e0 Compare June 27, 2026 04:18
@bcomnes
bcomnes force-pushed the docs/redirect-template-pattern branch from c9bb5e0 to 58f07cc Compare July 31, 2026 18:46
@bcomnes bcomnes changed the title Document redirect pages template pattern Add generated pages files Jul 31, 2026
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.

Native redirect support for URL migrations

3 participants