Markdown

Cook converts .md files in src/ to HTML pages in dist/. Each file can include YAML frontmatter for metadata and an optional layout template for wrapping the content.

Frontmatter

Add YAML between --- fences at the top of any .md file. These fields become template variables available in the layout.

Hello World

This is my first post built with Cook.

The title field is used as the page title. If omitted, Cook derives it from the filename. The date field is kept as a timezone-safe YYYY-MM-DD string for templates but is also parsed internally for sorting.

Layout templates

The layout frontmatter field maps to an HTML file in src/layouts/. Use ${content} where the converted markdown should appear, and ${fieldName} for any frontmatter or global data variable.

Cook searches for the layout file in src/layouts/ first, then dist/layouts/. You can change the layout directory with the markdown.layoutPath config option. If no layout is specified (and no default is configured), Cook wraps content in a basic HTML document.

Collections

Markdown files are automatically grouped into collections by their parent directory. Every .md file inside src/blog/ becomes part of the blog collection, files in src/docs/ become the docs collection, and so on.

Collections are sorted by date (newest first) and exposed as collections.{name} in template data. Use them with data-repeat to render lists:

Each collection item includes title, url, slug, date, description, and any other frontmatter fields you define. The content field is excluded from collection items to save memory.

HTML pages in collections

HTML pages can join collections too, for sites written as HTML or generated by a content tool. Turn it on in config/main.js:

Then any .html page that starts with YAML frontmatter joins the collection named after its first folder, alongside any Markdown pages there:

<p>We shipped.</p>

This page appears in collections.blog with URL /blog/launch-day/, sorted by date with the Markdown posts. A few rules:

  • Pages without frontmatter, pages in buildOnlyPaths folders, and pages matching excludePaths are left out.
  • draft: true in frontmatter keeps a page out of collections (the page itself is still built).
  • With siteRoot set, the collection is the first folder under that served folder: src/pages/blog/x.html with siteRoot: 'pages' joins blog.
  • Known limitation: Markdown pages do not follow siteRoot yet (they group by the first folder under src), so with siteRoot set, Markdown and HTML pages in the same folder land in different collections. Without siteRoot they merge.
  • It is off by default, so existing sites with HTML frontmatter are unchanged.

Configuration

Set defaults in config/main.js under the markdown key:

Clean URLs

Cook converts src/blog/hello-world.md to dist/blog/hello-world/index.html, giving you the clean URL /blog/hello-world/. Files named index.md produce index.html in the same directory.