carcade init <name> creates a brand-new project that contains the following entries:
The project can be built by carcade build command.
First, Carcade creates the site tree that reflects the structure of the pages folder. Tree nodes match to the page folders, from which they receive names and contexts.
Each node has two string values associated to it:
name – page folder name;
path – specifies the path from the tree root to the given node. Basically it’s just node names contatenated using /.For example, first-level nodes have path equal to name.Second-level nodes have path that looks like <name-1>/<name-2>, and so forth.
Then, if ordering and pagination setting were specified, the site tree gets ordered and paginated.
Now the site tree is ready for build. Carcade traverses the tree bottom-up and for each node does the following:
Source data stored in a Markdown and YAML files. Suppose there is a page called home. It’s source folder may look as follows:
home ├── examples.yaml ├── footer.md ├── data.en.yaml ├── data.ru.yaml ├── summary.en.md ├── summary.ru.md ├── details.en.md └── details.ru.md
Carcade will parse these files in the following order (each subsequent step can override the data from preceding steps):
The data from each Markdown file put into the context under it’s separate key (more exactly, the data from <name>[.<language].md has the key <name>). For example, after the step 2, the home context have footer, summary and details keys.
YAML files are supposed to contain dictionaries. These dictionaries are merged into the existing context one by one.
Pages are rendered using Jinja2 with some extensions (webassets and i18n).
Along with the context data, the template always contains the following variables:
Also you can use:
To enable i18n, you have to specify LANGUAGES settings. It must contain a list of languages (for example, ['ru', 'en']).
If i18n enabled, Carcade will build your site for each listed language separately, and:
read language-specific data files (as was described above);
To ease creation of translation files, Carcade provides command to extract all the localizable strings from the templates: carcade extract_messages.
Language versions available at prefixed URLs: /ru/page-name, /en/page-name and so on. If you want some language available without prexix, you can specify that language in DEFAULT_LANGUAGE setting.
Carcade uses webassets for static files management.
You can specify BUNDLES setting – a dictionary with bundles (webassets.Bundle) as values and bundle names as keys. Then you can use defined bundles in the templates using {% assets %} tag. Please see the webassets docs for details.
If PAGINATION specified, Carcade helps you to implement paginated output.
Pagination is done by an insertion of special nodes in the tree – just like if you would manually inserted page_<n> folders and put the necessary pages into them.
It may sound obscure, so take a look at the example or source code: core.paginate_tree(). :)