Components

Cook components are reusable HTML templates stored in src/components/. They expand at build time — zero JavaScript runtime cost.

Creating a component

Create an HTML file in src/components/:

Using a component

Use the filename as a custom element tag. Attributes become template variables:

The output replaces the custom element with the template, resolving all variables:

<article class="product-card"> <h3>Trail Runner Pack</h3> <p>32L ultralight backpack</p> <a href="/products/trail-runner-pack/">View Details</a> </article>

Slots

Default slot — &#36;{slot} receives all child content:

Named slots — &#36;{slot:name} receives children with slot="name":

Component styles

Components can include <style> blocks. Styles are extracted, deduplicated per component name, and consolidated into a single <style> in <head>:

Use native @scope and @layer for CSS isolation — no framework-specific scoping needed.

Semantic HTML pattern

For semantic markup, use data-component on any element:

This looks up src/components/site-header.html and passes data-* attributes as template variables.

DSD Components

Components can use Declarative Shadow DOM for true encapsulation. Include <template shadowrootmode="open"> in the component file:

DSD components preserve the custom element in the output and use native <slot> for content projection. See Declarative Shadow DOM for details.

File resolution

Cook looks for component templates in two locations:

  1. src/components/card.html (direct file)
  2. src/components/card/index.html (directory with index)

Configuration