Rocket
On this page

Layouts#

A layout turns pageData into a complete HTML document. Markdown Pages can export their own layout function, or rely on Rocket's default layout.

Page layout export#

Rocket calls a Markdown Page's exported layout with one argument: pageData.

```js server
import { html } from 'lit';
import { document } from '@rocket/js/layout-helper.js';

export const config = {
  path: '/',
  metadata: {
    title: 'Home',
    description: 'Welcome to the Acme Docs home page.',
  },
};

export const layout = pageData =>
  document(pageData, pageData.content, {
    menu: false,
    title: `${pageData.metadata.title} | Acme Docs`,
    headerContent: html`
      <meta name="description" content=${pageData.metadata.description} />
      <link rel="stylesheet" href="/styles/site.css" />
    `,
  });
```

# Home

Welcome to Acme Docs.

For reusable layouts, keep the layout implementation in a JavaScript module and bind site data from the Page:

import { atlasDocLayout } from '@rocket/js/layouts/atlasDoc.js';
import { siteData } from './siteData.js';

export const layout = pageData => atlasDocLayout(pageData, siteData);

PageData#

pageData is owned by Rocket and created for each render. Layouts commonly use:

Do not construct PageData by hand in normal site code. Use the object passed by Rocket.

Document helper#

document builds the HTML shell used by simple layouts:

import { html } from 'lit';
import { document } from '@rocket/js/layout-helper.js';
import { resolve } from '@rocket/js/resolve.js';

export const layout = pageData =>
  document(pageData, pageData.content, {
    menu: 'html',
    title: `${pageData.metadata.title} | Acme Docs`,
    headerContent: html`
      <link rel="stylesheet" href="${resolve('./styles/docs.css', import.meta)}" />
    `,
  });

The options are:

document emits Document Baseline Metadata for every document it creates: UTF-8 charset metadata and the standard responsive viewport metadata. This baseline is not Site Head Metadata and does not depend on the siteHeadMetadata config option.

document also inserts pageData.clientCode, so layouts using it automatically include code from js client, js demo, and Component Hydration.

For the full pageData shape, see PageData.

Default layout#

If a Markdown Page does not export a layout, Rocket uses @rocket/js/layout.js.

You can also re-export it explicitly:

```js server
export const config = {
  path: '/minimal',
};

export { layout } from '@rocket/js/layout.js';
```

# Minimal

This Page uses Rocket's default layout.

Layout components#

The atlas layouts export both a layout function and the Registered Components they require:

import { atlasDocLayout } from '@rocket/js/layouts/atlasDoc.js';
export { atlasDocComponents as components } from '@rocket/js/layouts/atlasDoc.js';

When a Page uses one of these layouts, keep the matching components export. It lets Rocket render layout-owned custom elements such as menus, table of contents, and Web Awesome callouts.

See Atlas Layouts for the atlas layout data shape, wrapper pattern, and component map details.