BackmatterPricingDocs
Contents

First document

A model, an MDX file, and a URL.

Init created the host. A document is a model plus a file.

Define the model

A model file declares the type. The file name is the type.

models/blog.ts
import { defineModel, field } from "@backmatter/next";

export default defineModel({
  type: "blog",
  path: "content/blog/{slug}.mdx",
  route: "/blog/{slug}",
  fields: {
    title: field.text({ required: true }),
  },
});

Add the file

The document is an MDX file at the model's path.

---
title: Hello
---

# Hello

First post.

Save that as content/blog/hello.mdx. The catch-all serves it at /blog/hello.

Read it

Read it through backmatter:

import { cms } from "backmatter";

const post = await cms.query.blog.get("hello");
post?.frontmatter.title; // "Hello"

get returns null when the file is missing. findMany lists documents of that type. Querying is the full set of calls: get, findMany, where, and include.

The folder layout is where that model, that file, and the catch-all sit.