Fumapress
The site generator

Layouts

Use and customize layouts in Fumapress.

Overview

Layouts are page renderers. They decide how a content page is wrapped, how the page body is rendered, and which UI pieces like sidebar, table of contents, navbar, and footer are shown.

Fumapress uses the docs layout by default. Pick another layout when a page needs a different reading experience, or switch between layouts per page with your own renderer.

Shared Props

Define defaultProps to share props across Fumadocs layouts. These props are merged into layouts that inherit default props, such as docs, notebook, and home layouts:

press.config.tsx
import { defineConfig } from "fumapress";

export default defineConfig({
  // ...
}).layouts({
  defaultProps() {
    return {
      nav: {
        title: "My Docs",
      },
      links: [
        {
          text: "GitHub",
          url: "https://github.com/acme/docs",
        },
      ],
    };
  },
});

Switching Layouts

The page layout is just a React component. To switch between layouts for every page, create your own renderer and forward the same props to the layout you want to use:

press.config.tsx
import { defineConfig } from "fumapress";
import { createDocsLayoutPage } from "fumapress/layouts/docs";
import { createNotebookLayoutPage } from "fumapress/layouts/notebook";

const config = defineConfig({
  // ...
});

export type Ctx = typeof config.$context;

const DocsPage = createDocsLayoutPage<Ctx>();
const NotebookPage = createNotebookLayoutPage<Ctx>();

export default config.layouts({
  page: (props) => {
    if (props.page.path.startsWith("reference/")) {
      return <NotebookPage {...props} />;
    }

    return <DocsPage {...props} />;
  },
});

For simpler use cases, it can be simplified with createLayoutSwitch():

press.config.tsx
import { defineConfig } from "fumapress";
import { createDocsLayoutPage } from "fumapress/layouts/docs";
import { createHomeLayoutPage } from "fumapress/layouts/home";
import { createLayoutSwitch } from "fumapress/layouts/switch";

export default defineConfig({
  // ...
}).layouts({
  page: createLayoutSwitch((page) => (page.path.startsWith("marketing/") ? "marketing" : "docs"), {
    docs: createDocsLayoutPage(),
    marketing: createHomeLayoutPage(),
  }),
});

File-based Layouts

File-based routes in src/pages use Waku's file-based routing model. Use _layout.tsx files to apply layouts on children routes.

Define & export layouts:

press.config.tsx
import { defineConfig } from "fumapress";
import { createHomeLayout } from "fumapress/layouts/home";

const config = defineConfig({
  // ...
});

export type Ctx = typeof config.$context;

export const HomeLayout = createHomeLayout<Ctx>();

export default config;

To apply HomeLayout on all file-based routes under /:

src/pages/_layout.tsx
export { HomeLayout as default } from "../../press.config";

Last updated on

On this page