Advanced Features

See what SiteGen can do with data and logic.

Data Sorting & Limiting

Here we load `data/links.json`, sort it by name descending, and limit to 3 items.

range sort "name" "desc" (limit 3 (data "links.json"))
  • Home - /
  • Features - /features
  • Blog - /blog

Page Variables & Frontmatter

Variables defined in the YAML frontmatter of a page are accessible directly at the root context. For example, the title of this page, accessed via {{.title}}, is Features.

Other built-in variables include:

File Sources & Metadata

Dynamically listing files from `src/blog` using `sources` and accessing their individual frontmatter using .Meta.<key> instead of root variables.

range sort "Meta.date" "desc" (sources "RelPath" "blog/*.html")

Pagination

You can easily paginate lists using the paginate function. This populates `.Page` and `.Pages` automatically.

$posts := paginate 2 (sources "RelPath" "blog/*.html")

File Handlers

Check `src/css/styles.css` frontmatter to see how we handle file-specific build commands.

/*
---
serve: echo "Serving CSS..."
build: echo "Building CSS..."
---
*/