From 7bf4ca729c2e48a86bf5a4dc8e7641d9a74c6997 Mon Sep 17 00:00:00 2001 From: Aviv Keller Date: Thu, 2 Apr 2026 17:18:35 -0400 Subject: [PATCH 01/11] feat(web): more customizable templates --- src/generators/web/README.md | 23 ++++---- src/generators/web/index.mjs | 4 +- src/generators/web/template.html | 14 ++--- src/generators/web/types.d.ts | 1 + src/generators/web/ui/components/NavBar.jsx | 4 +- .../web/ui/components/SideBar/index.jsx | 4 +- .../web/utils/__tests__/config.test.mjs | 22 +++----- src/generators/web/utils/config.mjs | 53 ++++++++++--------- src/generators/web/utils/processing.mjs | 30 ++++++----- 9 files changed, 80 insertions(+), 75 deletions(-) diff --git a/src/generators/web/README.md b/src/generators/web/README.md index 0941b8a7..ed6246aa 100644 --- a/src/generators/web/README.md +++ b/src/generators/web/README.md @@ -6,13 +6,16 @@ The `web` generator transforms JSX AST entries into complete web bundles, produc The `web` generator accepts the following configuration options: -| Name | Type | Default | Description | -| -------------- | -------- | --------------------------------------------- | --------------------------------------------------------------------- | -| `output` | `string` | - | The directory where HTML, JavaScript, and CSS files will be written | -| `templatePath` | `string` | `'template.html'` | Path to the HTML template file | -| `editURL` | `string` | `'${GITHUB_EDIT_URL}/doc/api{path}.md'` | URL template for "edit this page" links | -| `pageURL` | `string` | `'{baseURL}/latest-{version}/api{path}.html'` | URL template for documentation page links | -| `imports` | `object` | See below | Object mapping `#theme/` aliases to component paths for customization | +| Name | Type | Default | Description | +| ---------------- | -------- | --------------------------------------------- | --------------------------------------------------------------------- | +| `output` | `string` | - | The directory where HTML, JavaScript, and CSS files will be written | +| `templatePath` | `string` | `'template.html'` | Path to the HTML template file | +| `project` | `string` | `'Node.js'` | Project name used in page titles and the version selector | +| `title` | `string` | `'{project} v{version} Documentation'` | Title template for HTML pages (supports `{project}`, `{version}`) | +| `editURL` | `string` | `'${GITHUB_EDIT_URL}/doc/api{path}.md'` | URL template for "edit this page" links | +| `pageURL` | `string` | `'{baseURL}/latest-{version}/api{path}.html'` | URL template for documentation page links | +| `imports` | `object` | See below | Object mapping `#theme/` aliases to component paths for customization | +| `virtualImports` | `object` | `{}` | Additional virtual module mappings merged into the build | #### Default `imports` @@ -42,14 +45,16 @@ export default { The `web` generator provides a `#theme/config` virtual module that exposes pre-computed configuration as named exports. Any component (including custom overrides) can import the values it needs, and tree-shaking removes the rest. ```js -import { title, repository, editURL } from '#theme/config'; +import { project, repository, editURL } from '#theme/config'; ``` #### Available exports +All scalar (non-object) configuration values are automatically exported. The defaults include: + | Export | Type | Description | | ------------------------ | ------------------------------ | --------------------------------------------------------------------------------------------------- | -| `title` | `string` | Site title (e.g. `'Node.js'`) | +| `project` | `string` | Project name (e.g. `'Node.js'`) | | `repository` | `string` | GitHub repository in `owner/repo` format | | `version` | `string` | Current version label (e.g. `'v22.x'`) | | `versions` | `Array<{ url, label, major }>` | Pre-computed version entries with labels and URL templates (only `{path}` remains for per-page use) | diff --git a/src/generators/web/index.mjs b/src/generators/web/index.mjs index 6d783fbd..e41b76aa 100644 --- a/src/generators/web/index.mjs +++ b/src/generators/web/index.mjs @@ -29,7 +29,8 @@ export default createLazyGenerator({ defaultConfiguration: { templatePath: join(import.meta.dirname, 'template.html'), - title: 'Node.js', + project: 'Node.js', + title: '{project} v{version} Documentation', editURL: `${GITHUB_EDIT_URL}/doc/api{path}.md`, pageURL: '{baseURL}/latest-{version}/api{path}.html', imports: { @@ -40,5 +41,6 @@ export default createLazyGenerator({ '#theme/Footer': join(import.meta.dirname, './ui/components/NoOp'), '#theme/Layout': join(import.meta.dirname, './ui/components/Layout'), }, + virtualImports: {}, }, }); diff --git a/src/generators/web/template.html b/src/generators/web/template.html index 71d0de0e..eed99d1b 100644 --- a/src/generators/web/template.html +++ b/src/generators/web/template.html @@ -5,10 +5,10 @@ - {{title}} + {title} - - + + @@ -20,12 +20,12 @@ - - + + -
{{dehydrated}}
- +
{dehydrated}
+ diff --git a/src/generators/web/types.d.ts b/src/generators/web/types.d.ts index 5feed60e..081a7949 100644 --- a/src/generators/web/types.d.ts +++ b/src/generators/web/types.d.ts @@ -5,6 +5,7 @@ export type Generator = GeneratorMetadata< templatePath: string; title: string; imports: Record; + virtualImports: Record; }, Generate, AsyncGenerator<{ html: string; css: string }>> >; diff --git a/src/generators/web/ui/components/NavBar.jsx b/src/generators/web/ui/components/NavBar.jsx index a2315a4c..6ac549b2 100644 --- a/src/generators/web/ui/components/NavBar.jsx +++ b/src/generators/web/ui/components/NavBar.jsx @@ -6,7 +6,7 @@ import GitHubIcon from '@node-core/ui-components/Icons/Social/GitHub'; import SearchBox from './SearchBox'; import { useTheme } from '../hooks/useTheme.mjs'; -import { title, repository } from '#theme/config'; +import { repository } from '#theme/config'; import Logo from '#theme/Logo'; /** @@ -28,7 +28,7 @@ export default ({ metadata }) => { /> diff --git a/src/generators/web/ui/components/SideBar/index.jsx b/src/generators/web/ui/components/SideBar/index.jsx index d2965d17..15d3010b 100644 --- a/src/generators/web/ui/components/SideBar/index.jsx +++ b/src/generators/web/ui/components/SideBar/index.jsx @@ -4,7 +4,7 @@ import SideBar from '@node-core/ui-components/Containers/Sidebar'; import styles from './index.module.css'; import { relative } from '../../../../../utils/url.mjs'; -import { title, version, versions, pages } from '#theme/config'; +import { project, version, versions, pages } from '#theme/config'; /** * Extracts the major version number from a version string. @@ -54,7 +54,7 @@ export default ({ metadata }) => { >