mirror of
https://github.com/vercel/workflow.git
synced 2026-09-14 19:59:43 +08:00
ea16d04599
* docs: split v4/v5 content, fix version switcher end-to-end ## Content restructuring - Split `docs/content/docs/` into `docs/content/docs/v4/` and `docs/content/docs/v5/` so each version is a fully independent content tree with no shared-file coupling - v4 excludes the four pages that are v5-only (AbortController cancellation docs and the serializable-abort-controller internal page) - v5 retains all pages; `preRelease` frontmatter field removed (no longer needed now that each version is its own folder) - Removed `AbortController` / `AbortSignal` from v4 serialization page (section moved to v5 only) ## Fumadocs source - Added `v4docs` and `v5docs` as separate `defineDocs()` collections in `source.config.ts`; shared `docsSchema` (no more `preRelease` field) - `source.ts` exports both `source` (v4, `baseUrl: /docs`) and `v5Source` (v5, same base URL) ## Version routing - `version-source.ts` simplified: `filterPreReleaseFromNodes` and `isPreReleaseUrl` logic removed; v4 tree uses `source`, v5 tree uses `v5Source` + `rewriteNodeUrls` - v4 `page.tsx`: removed `preRelease` guard (v4Source has no such pages) - v5 `page.tsx`: uses `v5Source` for `getPage` / `generateStaticParams` / `generateMetadata`; `v5Link` wrapper rewrites `/docs/…` hrefs to `/v5/docs/…` so inline MDX links stay in the v5 context ## Versioned cookbook - Added `app/[lang]/v5/cookbook/` layout + page (mirrors v4 but uses `v5Source`, `rewriteCookbookUrlForVersion`, and `V5CookbookLink`) - `getCookbookTree` accepts a `versionPrefix` parameter; sidebar URLs are prefixed accordingly (`/v5/cookbook/…`) - `cookbook-tree.ts`: added `skipVersions?: string[]` per-recipe field for version-specific exclusions; `distributed-abort-controller` is marked `skipVersions: ['v5']` ## Version switcher — state & navigation - New `VersionProvider` context (`hooks/geistdocs/use-version.tsx`) backed by `localStorage`: URL is source of truth on versioned pages, `localStorage` carries the preference across non-versioned pages (cookbook overview, worlds, etc.) - `VersionSwitcher` uses `useVersion()` context instead of URL-only detection; now visible on all pages including cookbook - `DesktopMenu` and `MobileMenu` use `activeVersion` from context so the "Docs" and "Cookbook" navbar links resolve to the correct version prefix on every page - `buildVersionUrl` expanded to handle `/cookbook/…` paths alongside `/docs/…`; non-versioned routes (worlds, api) return unchanged - `switchVersion` does a `HEAD` probe before navigating; falls back to the versioned cookbook or docs home if the target page doesn't exist in that version (handles v4-only → v5 and v5-only → v4 cases) ## Cookbook content (v5) - Rewrote `agent-cancellation` recipe using a single `AbortController` pattern; removed Hard Cancellation vs Stop Signal two-approach comparison - Deleted `distributed-abort-controller` recipe from v5 (native `AbortController` serialization makes it unnecessary) - Removed references to distributed-abort-controller from `cookbook/index.mdx` and `common-patterns/timeouts.mdx` Co-authored-by: Cursor <cursoragent@cursor.com> * fix(docs): use abortSignal (not signal) in DurableAgent.stream() options Co-authored-by: Cursor <cursoragent@cursor.com> * fix(docs): update prepack scripts to use versioned content paths Content moved from docs/content/docs/ to docs/content/docs/v5/ on main (pre-release channel). Stable branch will use v4/ after backport. Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com>
121 lines
3.3 KiB
TypeScript
121 lines
3.3 KiB
TypeScript
import type { Node, Root } from 'fumadocs-core/page-tree';
|
|
import {
|
|
categoryLabels,
|
|
categoryOrder,
|
|
recipes,
|
|
type RecipeCategory,
|
|
} from '../cookbook-tree';
|
|
import { source, v5Source } from './source';
|
|
|
|
const COOKBOOK_DOCS_PREFIX_RE = /\/docs\/cookbook(?=\/|$)/g;
|
|
|
|
type FolderNode = Extract<Node, { type: 'folder' }>;
|
|
type PageNode = Extract<Node, { type: 'page' }>;
|
|
|
|
export function rewriteCookbookUrl(url: string): string {
|
|
return url.replace(COOKBOOK_DOCS_PREFIX_RE, '/cookbook');
|
|
}
|
|
|
|
/**
|
|
* Rewrite a fumadocs source URL (`/docs/cookbook/...`) to the public cookbook
|
|
* URL for a given version prefix. Pass '' for v4 (`/cookbook/...`) or '/v5'
|
|
* for v5 (`/v5/cookbook/...`).
|
|
*/
|
|
export function rewriteCookbookUrlForVersion(
|
|
url: string,
|
|
versionPrefix: string
|
|
): string {
|
|
return url.replace(COOKBOOK_DOCS_PREFIX_RE, `${versionPrefix}/cookbook`);
|
|
}
|
|
|
|
export function rewriteCookbookUrlsInText(text: string): string {
|
|
return text.replace(COOKBOOK_DOCS_PREFIX_RE, '/cookbook');
|
|
}
|
|
|
|
function isCookbookFolder(node: Node): boolean {
|
|
return (
|
|
node.type === 'folder' &&
|
|
(node.index?.url?.startsWith('/docs/cookbook') ?? false)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Return the docs page tree with cookbook nodes removed.
|
|
* Used by the docs layout so the sidebar never shows cookbook entries.
|
|
* Pass 'v5' to use the v5 source tree; defaults to 'v4'.
|
|
*/
|
|
export function getDocsTreeWithoutCookbook(
|
|
lang: string,
|
|
version: 'v4' | 'v5' = 'v4'
|
|
): Root {
|
|
const src = version === 'v5' ? v5Source : source;
|
|
const fullTree = src.pageTree[lang];
|
|
return {
|
|
...fullTree,
|
|
children: fullTree.children.filter((node) => !isCookbookFolder(node)),
|
|
};
|
|
}
|
|
|
|
function createOverviewPage(versionPrefix: string): PageNode {
|
|
return {
|
|
type: 'page',
|
|
$id: 'cookbook__overview',
|
|
name: 'Overview',
|
|
url: `${versionPrefix}/cookbook`,
|
|
} as PageNode;
|
|
}
|
|
|
|
function createRecipePage(
|
|
category: RecipeCategory,
|
|
slug: string,
|
|
versionPrefix: string
|
|
): PageNode {
|
|
const recipe = recipes[slug];
|
|
return {
|
|
type: 'page',
|
|
$id: `cookbook__${slug}`,
|
|
name: recipe.title,
|
|
url: `${versionPrefix}/cookbook/${category}/${slug}`,
|
|
} as PageNode;
|
|
}
|
|
|
|
function createCategoryFolder(
|
|
category: RecipeCategory,
|
|
versionPrefix: string
|
|
): FolderNode {
|
|
// Derive version ID from prefix: '/v5' → 'v5', '' → 'v4'
|
|
const versionId = versionPrefix ? versionPrefix.replace(/^\//, '') : 'v4';
|
|
const categoryRecipes = Object.values(recipes).filter(
|
|
(recipe) =>
|
|
recipe.category === category && !recipe.skipVersions?.includes(versionId)
|
|
);
|
|
return {
|
|
type: 'folder',
|
|
$id: `cookbook__${category}`,
|
|
name: categoryLabels[category],
|
|
children: categoryRecipes.map((recipe) =>
|
|
createRecipePage(category as RecipeCategory, recipe.slug, versionPrefix)
|
|
),
|
|
} as FolderNode;
|
|
}
|
|
|
|
/**
|
|
* Build a standalone cookbook sidebar tree from cookbook-tree metadata.
|
|
* Pass a versionPrefix (e.g. '/v5') to produce version-prefixed sidebar URLs.
|
|
*/
|
|
export function getCookbookTree(lang: string, versionPrefix = ''): Root {
|
|
const src = versionPrefix ? v5Source : source;
|
|
const fullTree = src.pageTree[lang];
|
|
|
|
return {
|
|
...fullTree,
|
|
name: 'Cookbook',
|
|
children: [
|
|
createOverviewPage(versionPrefix),
|
|
...categoryOrder.map((category) =>
|
|
createCategoryFolder(category, versionPrefix)
|
|
),
|
|
],
|
|
};
|
|
}
|