feat(farmjs): render themes like the Next.js layout (shell layout/page, generated titles, hidden folders)
KI
1mo ago+343+343+012345678901234567890123456789-69-69-01234567890123456789
Problem
a theme that renders the same on next.js can't be reproduced on farm. trying the assistant-ui docs theme (assistant-ui/assistant-ui#9741, built for @farming-labs/next) on a 376-page farm port showed four gaps, each a place where the farm adapter does something different from the next.js layout:
- no layout composition. on next, a theme wraps
createDocsLayoutwith its own header and passes page controls as the layout's children. farm renders the layout inside its own renderer, so there was nowhere to put either inside the providers (the existingshellwraps outside them, so search/tree/toc contexts aren't available). - no generated page title. next renders the frontmatter title (and the title-row controls themes attach to
.fd-generated-page-header) for shadcn-based themes when the markdown has no h1. farm never did, so pages without# titlehad no heading at all. - hidden folder index. next names a folder from a
hidden: trueindex without linking it, and drops a hidden page with no children. farm linked to the hidden page. - "Introduction" folders. with a shadcn-based theme next names a folder whose index is titled "Introduction" after its slug (e.g. "React Native"); farm showed "Introduction".
Change
- the docs shell module (
withDocs(config, { shell })) may also exportlayoutandpage. the renderer wraps the docs layout withlayoutinside the providers, and each page's content withpageinside the layout, the same places next puts a theme's header and page controls. without them nothing changes. load()returnsgeneratedTitlewith next's rule (hasAuthoredPageTitle, copied rather than imported so older theme/core versions keep working); the renderer passes it to the layout, andDocsPageClient/TanstackDocsLayoutaccept it per page.- both nav builders (filesystem and bundled) honor
hidden: truelike next. - the loaded tree names "Introduction" folders like next for shadcn-based themes (scanned trees only, as on next).
Safety and compatibility
- all opt-in or matching existing next behavior; apps without a shell
layout/page, without shadcn-based themes, or without hidden pages render as before. generatedTitleonly applies when the markdown has no title, so pages with# titleare unchanged.- next and tanstack adapters are untouched apart from the new optional
generatedTitleprop on the shared layout.
Verification
packages/farmjs141 tests (new: wrapper placement and absence, generated title rules incl. fenced#and setext, hidden index in both builders, introduction folder naming),packages/fumadocs286,packages/next181,packages/tanstack-start4; typecheck clean for farmjs and theme; oxlint/oxfmt clean.- assistant-ui docs (376 pages) with the shared theme on farm (this branch, plus #621 and #625) vs the same content, config and theme on next 16.4 +
@farming-labs/next0.2.127: screenshots at 1440x900 light/dark and 390x844 for three pages, viewport and full page, are pixel-identical for architecture (0.00% in all six) and thread (<=0.01%, same height); installation differs only inside an animated gif frame. sidebars match entry for entry (377/377) after these fixes; before them farm had 379 entries in a different order and no title row controls. - no console errors or hydration warnings on either.
Documentation and release
the shell option's docs comment covers layout/page. ships with the next release.
Summary by cubic
Makes farm render themes the way the Next.js docs layout does, so a theme built for @farming-labs/next reproduces identically on farm without theme changes.
Changes
- The docs shell may now export
layoutandpage; the renderer wraps the docs layout and each page's content with them inside the providers, where Next.js places a theme's header and page controls. load()returnsgeneratedTitlefor shadcn-based themes when the Markdown authors no title (#, setext, or<h1>outside code fences), and the renderer passes it to the layout.- Both nav builders honor
hidden: truelike Next.js: a hidden index names its folder without linking to it, and hidden pages are dropped. - For shadcn-based themes, folders whose index is titled "Introduction" are named after their slug, as on Next.js.
Compatibility
- All changes are opt-in or match existing Next.js behavior; apps without a shell
layout/page, without shadcn-based themes, or without hidden pages render as before. - Next.js and TanStack adapters gain only the optional
generatedTitleprop.