shuding / nextra

Simple, powerful and flexible site generation framework with everything you love from Next.js.
https://nextra.site
MIT License
11.77k stars 1.28k forks source link

What are the options for "frontmatter"? #2399

Open benjie opened 1 year ago

benjie commented 1 year ago

I managed to disable the Table of Contents on the right by adding toc: false to the frontmatter for my MDX file, but that was a guess based on similar systems like Docusaurus. I've been unable to find this setting in the Nextra documentation or the Next.js documentation; and cannot find a list of similar options that I can use. Spelunking through the code, the closest I found was:

https://github.com/shuding/nextra/blob/8137d3fd568a3cc3b23300f1ff30a6039194c81a/packages/nextra/src/normalize-pages.ts#L5-L16

but this doesn't include the title key which I also figured out works, so it's clear that's not the complete picture. Is there documentation of the frontmatter options somewhere?

Possibly related PR:

dimaMachina commented 1 year ago

setup of these options in _meta.json is preferable since you can control * global key for nested pages

{
  "*": {
    "theme": {} // apply globally for all nested pages
  },
  "my-page": {
    "theme": {
      "collapsed"?: boolean, // collapse by default in sidebar
      "layout"?: "default" | "full" | "raw" = "default", // raw - do not replace mdx components, render unstyled mdx page
      "typesetting"?: "default" | "article" = "default",  // use special styles for page
      // control of show | hide bellow
      "breadcrumb"?: boolean,
      "footer"?: boolean,
      "navbar"?: boolean,
      "pagination"?: boolean, // prev | next pages at the bottom
      "sidebar"?: false,
      "timestamp"?: boolean, // last updated at text
      "toc"?: boolean
    }
  }
}

setup title in frontmatter will define document <title /> and in case when sidebar label for page was not defined frontmatter's title will be used too

---
title: foo bar
---
benjie commented 1 year ago

Is there a JSON Schema for _meta.json?

benjie commented 1 year ago

in case when sidebar label for page was not defined

How would one define that separately from the page title?

dimaMachina commented 1 year ago
  1. Is there a JSON Schema for _meta.json?

While developing you should receive console warning from zod in the browser in case of mistyping of key/values of _meta.json file

[!NOTE] Support of _meta.json will be removed in Nextra v3 in favour of _meta.{js,jsx,ts,tsx} with support of JSX elements so we could export typesafe defineCofig or defineMeta instead of zod validation

  1. How would one define that separately from the page title?

In nextra v3 I added similar frontmatter property sidebar_label.

For now, you can overwrite it only in _meta.json

// _meta.json

"my-page": "My sidebar label",
// or via object
"my-page": {
  "title": "My sidebar label"
}