Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ The site pulls the Markdown docs straight from the `nodejs/undici` repository at
each supported release tag and renders them into static HTML with
[`@node-core/doc-kit`](https://www.npmjs.com/package/@node-core/doc-kit), the
same documentation toolchain used across the Node.js project. The latest major
version is served at the site root (`/`); older majors live under a versioned
path (e.g. `/v7.x/`).
version is served from a versioned path (e.g. `/v8.x/`), and Vercel temporarily
redirects the site root (`/`) to that path.

## Getting started

Expand All @@ -35,7 +35,7 @@ The build is driven by a couple of environment variables consumed in
[`doc-kit.config.mjs`](doc-kit.config.mjs):

- `VERSION` — the Undici version being built (e.g. `v8.5.0`)
- `IS_LATEST` — `"true"` when building the newest major (served at `/`)
- `IS_LATEST` — `"true"` when building the newest major

## How it works

Expand Down Expand Up @@ -91,9 +91,9 @@ Each invocation runs with `VERSION` set to the current tag and `IS_LATEST` set t
`true` only for the first (newest) entry. [`doc-kit.config.mjs`](doc-kit.config.mjs)
reads those variables to decide:

- **Output path & routing** — the latest major builds to `out/` and is served at
the root (`/`); every other major builds to `out/v<major>.x/` and is served
under that path.
- **Output path & routing** — every major builds to `out/v<major>.x/` and is
served under that versioned path. Vercel temporarily redirects `/` to the
current latest path.
- **Generated targets** — `web` (the static HTML), `orama-db` (the client-side
search index), and `legacy-json` (the legacy JSON API docs). The
index/all/404 helper pages are only generated for the latest version.
Expand Down
17 changes: 13 additions & 4 deletions components/SideBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,20 @@ const major = (v) => String(v.version ?? v).replace(/^v/, "").split(".")[0];

const basePath = (v) => {
const majorVersion = major(v);
return majorVersion === major(versions[0]) ? "/" : `/v${majorVersion}.x/`;
return `/v${majorVersion}.x/`;
};

const toURL = (path) =>
basePath(version) + path.replace(/\/index$/, "").replace(/^\/?/, "");
const toURL = (path) => {
if (/^(?:[a-z][a-z\d+.-]*:|\/\/|#)/i.test(path)) return path;
return basePath(version) + path.replace(/\/index$/, "").replace(/^\/?/, "");
};

const withVersionedLinks = (items) =>
items.map((item) => ({
...item,
...(item.link ? { link: toURL(item.link) } : {}),
...(item.items ? { items: withVersionedLinks(item.items) } : {}),
}));

/**
* Sidebar component for MDX documentation with page navigation
Expand All @@ -31,7 +40,7 @@ export default ({ metadata }) => (
pathname={toURL(metadata.path)}
groups={
sidebar.length > 0
? sidebar
? withVersionedLinks(sidebar)
: [
{
groupName: "Documentation",
Expand Down
2 changes: 1 addition & 1 deletion doc-kit.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const IS_LATEST = process.env.IS_LATEST === "true";
const ORIGIN = process.env.VERCEL_URL
? `https://${process.env.VERCEL_URL}`
: "http://localhost:3000";
const URL_PATH = IS_LATEST ? "/" : `/${MAJOR_VERSION}/`;
const URL_PATH = `/${MAJOR_VERSION}/`;

const BASE_URL = `${ORIGIN}${URL_PATH}`;

Expand Down
16 changes: 14 additions & 2 deletions scripts/build-html.mjs
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { execFile } from "node:child_process";
import { readFile, cp } from "node:fs/promises";
import { dirname, join } from "node:path";
import { readFile, cp, stat } from "node:fs/promises";
import { dirname, extname, join } from "node:path";
import { fileURLToPath } from "node:url";
import { promisify } from "node:util";
import { major } from "semver";

const ROOT = join(dirname(fileURLToPath(import.meta.url)), "..", "..");

const execFileAsync = promisify(execFile);

const versions = JSON.parse(await readFile("./versions.json"));

const isMarkdownOrDirectory = async (path) =>
(await stat(path)).isDirectory() || extname(path) === ".md";

const runDocKit = (version) =>
execFileAsync(
"npx",
Expand Down Expand Up @@ -39,4 +43,12 @@ const runDocKit = (version) =>

for (const version of versions) {
await runDocKit(version);

const versionPath = `v${major(version)}.x`;
const outputPath = join("out", versionPath);

await cp(join("docs", versionPath), outputPath, {
recursive: true,
filter: isMarkdownOrDirectory,
});
}
5 changes: 5 additions & 0 deletions vercel.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
"installCommand": "npm ci",
"buildCommand": "npm run build",
"redirects": [
{
"source": "/",
"destination": "/v8.x",
"permanent": false
},
Comment thread
ColumbusLabs marked this conversation as resolved.
{
"source": "/docs/docs/:path*",
"destination": "/:path*"
Expand Down