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.
src/blog/hello-world.md
---title: Hello Worlddescription: My first blog postdate: 2026-03-15layout: postauthor: Janetags: [intro, cook]
---title: Hello Worlddescription: My first blog postdate: 2026-03-15layout: postauthor: Janetags: [intro, cook]
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.
<!doctype html><html lang="en"><head> <meta charset="utf-8"> <title>${title} - Cook SSG</title> <meta name="description" content="${description}"></head><body> <main> <article> <time>${date}</time> ${content} </article> </main></body></html>
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:
<ul> <li data-repeat="collections.blog as post"> <a href="${post.url}">${post.title}</a> <time>${post.date}</time> </li></ul>
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:
export default { collections: { html: true },};
Then any .html page that starts with YAML frontmatter joins the collection named after its first folder, alongside any Markdown pages there:
src/blog/launch-day.html
---title: Launch Daydate: 2026-11-01layout: posttags: [news]
---title: Launch Daydate: 2026-11-01layout: posttags: [news]
<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
buildOnlyPathsfolders, and pages matchingexcludePathsare left out. draft: truein frontmatter keeps a page out of collections (the page itself is still built).- With
siteRootset, the collection is the first folder under that served folder:src/pages/blog/x.htmlwithsiteRoot: 'pages'joinsblog. - Known limitation: Markdown pages do not follow
siteRootyet (they group by the first folder undersrc), so withsiteRootset, Markdown and HTML pages in the same folder land in different collections. WithoutsiteRootthey 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:
export default { markdown: { layout: 'default', // default layout for all .md files layoutPath: 'layouts', // directory for layout templates collections: true, // auto-group by directory markedOptions: { gfm: true, // GitHub Flavored Markdown breaks: false, // convert \n to <br> }, },};
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.