Directives
Directive syntax
Directives are HTML comments with attributes. They are replaced when the site is built, so the source stays valid HTML that any editor understands.
The built-in directives
| Directive | Does |
|---|---|
<!-- component="file.html" --> | inserts a component (Pages and components) |
<!-- create-from-data-source="file.json" renderer="name" --> | renders a JSON file (Data and renderers) |
<!-- public-file-list="folder" renderer="name" --> | renders the list of files of an output folder (public-file-list) |
{{ url-to="fragment" }} | the URL of a page of the site (url-to) |
<!-- include-styles-src -->, <!-- include-script-src --> | the stylesheet and script tags (Asset tags) |
<!-- generate-from-files="folder" --> | one page per Markdown file (Markdown and blogs) |
Your own directives are custom directives.
Attributes
Values are written in double quotes and end at the closing quote:
<!-- create-from-data-source="people/team.json" renderer="peopleCards" -->Write a directive on a single line.
options
options holds JSON, written as is inside the quotes (no escaping needed), anywhere in the directive. Objects and arrays both work:
<!-- create-from-data-source="talks.json" renderer="talkList" options="{"limit":3,"order":["keynote","talk"]}" -->Single quotes work too: options='{"limit":3}'. Invalid JSON is reported as OPTIONS_INVALID_JSON with the file and line, and the options are ignored.
LANG and USERNAME
Before its attributes are read, every directive has:
LANGreplaced by the language being built (en,it…), options included;USERNAMEreplaced by theusernameoption of the configuration.
<!-- create-from-data-source="LANG/news.json" renderer="newsList" -->USERNAME keeps personal paths out of the sources:
export default { username: 'alex' };<!-- generate-from-files="/Users/USERNAME/notes/blog" -->Warning
Without username, USERNAME becomes the text undefined.