Frontmatter #

Frontmatter is a small set of settings at the very top of a Markdown file. It does not appear in the document. Use it for a title, description, layout, or your own data.

Write Frontmatter #

YAML is the usual format. Put the data between three dashes before anything else in the page:

Markdown
---
title: Getting started
description: Create your first KawaPress site in a few minutes.
---

# Getting started

A JSON object works too:

Markdown
{
  "title": "Getting started",
  "description": "Create your first KawaPress site in a few minutes."
}

# Getting started

These values travel with the page, so keep them simple: text, numbers, true or false, null, lists, and plain objects.

Use Your Own Data #

Alongside the fields below, you can save any page data you need. Read the current page with usePageData():

Markdown
---
status: beta
---

<script setup lang="ts">
import { usePageData } from 'kawapress/client'

const page = usePageData()
</script>

Current status: {{ page?.frontmatter.status }}

usePageData() updates during client-side navigation. It reads only the page that is open.

Check Frontmatter #

Frontmatter is written by hand, so it is easy to mistype a letter or write "no" where false was meant. KawaPress checks every page when it builds: it knows which fields KawaPress itself, the theme, and each installed plugin read, and how each of them should be written.

This page writes sidebar as text and misspells title:

Markdown
---
titel: Getting started
sidebar: no
---

kawapress build then prints:

Text
/guide/intro.md:3 `sidebar` must be true or false, got the string "no" (rule from @kawapress/preset-nagi)
KawaPress: /guide/intro.md:2 unknown frontmatter key `titel`; did you mean `title`?

Each line names the file, the line, the field, what it should be, and the package the rule comes from.

  • A field of the wrong type fails the build. Every problem of every page is listed at once, so you can fix them all and build again.
  • Unknown fields stay allowed, so your own data is safe. KawaPress only asks “did you mean…” when an unknown field is a letter or two away from a known one. That is a hint and never fails the build.
  • kawapress dev only prints the problems and keeps running. A page's problems show up in the terminal as soon as you open or change it.

To keep building when a page has a problem, or to turn the check off:

TypeScript
import { nagi } from 'kawapress/nagi'

export default nagi({
  frontmatter: { level: 'warn' }, // print the problems, keep building
  // frontmatter: false,          // no check
})

Add Rules for Your Own Fields #

KawaPress can check your own fields too. Write the rules in frontmatter.schema, and every page is checked against them together with the rules of the theme and the plugins.

Write the rules with Zod (npm i zod). KawaPress itself, nagi, and the official plugins describe their fields with Zod too:

TypeScript
import { nagi } from 'kawapress/nagi'
import { z } from 'zod'

export default nagi({
  frontmatter: {
    schema: z.object({
      status: z.enum(['draft', 'beta', 'stable']).optional().describe('How mature the page is.'),
    }),
  },
})

Fields the rules do not mention are not affected. A field without .optional() must be on every page, so leave it off only for fields that every page really needs. The text in .describe() becomes the hint in editors.

If you prefer Valibot or ArkType, that works too: schema takes any library that follows Standard Schema.

To get the type when you read the field, add the same field to PageFrontmatter:

TypeScript
declare module 'kawapress' {
  interface PageFrontmatter {
    status?: 'draft' | 'beta' | 'stable'
  }
}

JSON Schema for Editors #

kawapress dev and kawapress build merge every rule into one JSON Schema at node_modules/.kawapress/frontmatter.schema.json. It lists every field the site can use, with its description, for editor extensions and other tools to read. The file follows the installed plugins, so there is no need to commit it.

Page Titles and Descriptions #

Use these three fields to set a page title and summary:

FieldWhat it does
titleThe page title. The first H1 is used when it is absent.
descriptionA short page summary for search engines and link previews.
titleTemplateA browser-tab title template. %s becomes the page title; use false for the page title alone.
Markdown
---
title: Configure your site
description: Set a KawaPress site title, path, and language.
titleTemplate: '%s · KawaPress Guide'
---

The browser-tab title for this page is “Configure your site · KawaPress Guide”. The page title is also used by site search.

Pages without description use the description from the site config. On a multilingual site, the current language's own description comes before the site-wide one:

TypeScript
import { nagi } from 'kawapress/nagi'

export default nagi({
  description: 'A Vue-powered static site generator.',
  locales: {
    root: { label: 'English', lang: 'en' },
    zh: { label: '简体中文', lang: 'zh-CN', description: '用 Vue 写文档的静态站点生成器。' },
  },
})

Without title, the page title is the text of the first H1 with its Markdown formatting and inline HTML tags removed: **bold**, [links](/guide), and <kbd>Ctrl</kbd> keep only the words inside them, <Badge text="beta" /> leaves nothing, and inline code loses its backticks. Formulas and emoji shortcodes stay as written: the heading # Energy $E=mc^2$ <Badge text="beta" /> gives the page title Energy $E=mc^2$.

To add <head> tags to a single page, write them in the frontmatter head field. Every entry has the same [tag, attributes, content?] shape as in the site config:

Markdown
---
head:
  - - meta
    - property: og:image
      content: https://example.com/guide.png
---

This page’s share image replaces the og:image set for the site. Tags render in the order site, current language, then current page, so later sources win. See Add Head Tags for the site and language settings.

The validated list is available as page.head when you read page data.

Nagi Page Layout #

With the default nagi experience, layout chooses the page layout and navigation:

Markdown
---
layout: home
---
ValueResult
docThe default document layout.
homeA landing-page layout with hero and features.
pageA blank page layout with only the navigation bar and footer. The site styles its own content; nagi adds neither .nagi-doc typography nor document padding.
Any other nameA custom layout, see below.
falseNo nagi frame at all, only the page itself. Useful for a page shown inside an iframe.

Custom Layouts #

When layout is any other name, nagi looks for a global component with that name and renders it below the navigation bar in place of the page content. The component places the page content with <RouterView />:

Vue
<!-- ComponentDocs.vue -->
<script setup lang="ts">
import { RouterView } from 'kawapress/client'
</script>

<template>
  <div class="component-docs">
    <aside>…</aside>
    <RouterView />
  </div>
</template>

Register it in a Runtime Plugin under the name the frontmatter uses (component-docs, componentDocs, and ComponentDocs all match):

TypeScript
api.vueApp((app) => {
  app.component('component-docs', ComponentDocs)
})
Markdown
---
layout: component-docs
---

Pages with a custom layout or layout: false stay out of the automatic sidebar. When no component has the name, the page shows its content like a page layout.

You can also turn off individual nagi regions for one page:

Markdown
---
navbar: false
sidebar: false
outline: false
footer: false
pageClass: focused-page
---
FieldWhat it does
navbar: falseHides the top navigation.
sidebar: falseHides this document page’s sidebar and menu. The page remains in the site navigation.
aside: falseHides the wide-screen page-outline rail.
outline: falseHides every page outline, including the small-screen outline button.
footer: falseHides the footer on a home or page layout.
pageClassAdds a CSS class to the page’s outer element for your own styles.

See Getting Started for hero and features.

To keep a page out of the default local search, write:

Markdown
---
search: false
---

Only a literal false excludes a page.

Exclude a Page from the Sitemap #

To keep a page out of sitemap.xml, write:

Markdown
---
sitemap: false
---

Only a literal false excludes a page. For the other sitemap settings, see Sitemap.

Edit this pageLast updated:

Comments