Data

Cook loads config/data.js at build time and makes its exported values available as template strings on every page. Combine this with front matter for page-level overrides.

Basic data file

Export a plain object with string values. Each key becomes a ${variableName} you can use in any HTML, JSON, or webmanifest file.

Use these values in templates with ${variableName} syntax:

Nested data

Use dot notation to organize related data. Access nested values with ${parent.child} in your templates.

Async data loading

Export a function instead of an object to load data dynamically at build time. Cook will await the function if it returns a promise.

This is useful for pulling data from APIs, reading files, or running any Node.js code at build time.

Dynamic imports

For data that requires heavy dependencies, use dynamic import() inside the function:

How data flows

  1. Cook loads config/data.js once at the start of the build
  2. If the export is a function, Cook calls it and awaits the result
  3. The resulting object is passed to every build plugin that needs data
  4. For template string resolution, front matter values are merged on top of global data, so page-level values override global ones
  5. Template strings (${key}) are replaced with their matching data values

Arrays and collections

Data can include arrays, which are especially useful with data-repeat:

See Template Strings for how these values get resolved and Data Repeat for iterating over arrays.