From 4bd42e97ef6e4c24c9a537a975ac83da40e2a4cc Mon Sep 17 00:00:00 2001 From: ColumbusLabs <287001685+ColumbusLabs@users.noreply.github.com> Date: Fri, 24 Jul 2026 23:28:46 -0400 Subject: [PATCH] fix: include Markdown files in generated site Assisted-by: OpenAI Codex --- README.md | 12 ++++++------ components/SideBar.jsx | 17 +++++++++++++---- doc-kit.config.mjs | 2 +- scripts/build-html.mjs | 16 ++++++++++++++-- vercel.json | 5 +++++ 5 files changed, 39 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index b6658e6..6c62e40 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 @@ -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.x/` and is served - under that path. +- **Output path & routing** — every major builds to `out/v.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. diff --git a/components/SideBar.jsx b/components/SideBar.jsx index 21ca403..d97b721 100644 --- a/components/SideBar.jsx +++ b/components/SideBar.jsx @@ -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 @@ -31,7 +40,7 @@ export default ({ metadata }) => ( pathname={toURL(metadata.path)} groups={ sidebar.length > 0 - ? sidebar + ? withVersionedLinks(sidebar) : [ { groupName: "Documentation", diff --git a/doc-kit.config.mjs b/doc-kit.config.mjs index 3854331..70b91f6 100644 --- a/doc-kit.config.mjs +++ b/doc-kit.config.mjs @@ -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}`; diff --git a/scripts/build-html.mjs b/scripts/build-html.mjs index 57f1dc4..3d50f42 100644 --- a/scripts/build-html.mjs +++ b/scripts/build-html.mjs @@ -1,8 +1,9 @@ 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)), "..", ".."); @@ -10,6 +11,9 @@ 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", @@ -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, + }); } diff --git a/vercel.json b/vercel.json index da94b8c..e8511d4 100644 --- a/vercel.json +++ b/vercel.json @@ -6,6 +6,11 @@ "installCommand": "npm ci", "buildCommand": "npm run build", "redirects": [ + { + "source": "/", + "destination": "/v8.x", + "permanent": false + }, { "source": "/docs/docs/:path*", "destination": "/:path*"