Skip to content
Gitupcms
Esc
↑↓navigate↵open⌘Jpreview
On this page

Site data

Navigation, footer and settings stored in one JSON, YAML or TOML file.

Collections with Astro’s file() loader show up as Site data. One file holds them:

  • A plain array or a keyed object is a list of entries.
  • Parsers like (t) => JSON.parse(t).part or (t) => ({ id: JSON.parse(t).part }) edit one part of the file. The site’s own parse calls work too (yaml.load, smol-toml parse).
  • A glob() of one named file (pattern: 'settings.yaml') is one settings object, in any format, without a parser.
const settings = defineCollection({
  loader: glob({ base: "./src/data", pattern: "settings.yaml" }),
  schema: z.object({ siteName: z.string(), phone: z.string().optional() }),
});

const nav = defineCollection({
  loader: file("./src/data/nav.json"),
  schema: z.object({ label: z.string(), href: z.string() }),
});

Was this page helpful?