Pages
14 Sep 2016In site.nix
, a page is declared as an attribute set in the pages
attribute, example:
pages = {
about = {
path = "/about.html";
template = templates.page.full;
layout = templates.layout;
} // data.about;
};
Note: This example merges a data set in the page set, this is usual way to create pages from data.
Basics
During site generation, styx evaluates generatePage
on each pages
page.
generatePage
definition is page: pages.layout (page.template page)
, it simply evaluates a page set by its template, and evaluate that result with the layout.
The generated page content is output in the page path
file.
A simple example of a page is:
pages = {
hello = {
layout = template: "<html><body>${template}</body></html>";
template = page: ''
<h1>Styx example page</h1>
${page.content}
'';
content = "<p>Hello world!</p>";
path = "/hello.html";
};
}
Will generate /hello.html
with the following contents:
<html><body><h1>Styx example page</h1>
<p>Hello world!</p>
</body></html>
Helper functions
The standard library provide helper functions to generate multiple type of pages:
mkSplit
: to split a data list between multiple pages, used to create archive like pages.mkPageList
: to generate a list of pages from a list of data.mkMultipages
: to split a multipage data between multiple pages.mkTaxonomyPages
: to generate taxonomy pages from taxonomy data.