Collections & Data
The collections every template can read, grouping by other front matter keys, and data files in _data/.
Collections
| Collection | Contents |
|---|---|
collections.all | Every document in the build |
collections.<type> | Documents of that type, for example collections.post and collections.page. The key is lower-case. |
collections.post | Sorted newest first by date |
collections.tags | Every tag, once, in its original spelling, sorted case-insensitively |
collections.byTag[ slug ] | Documents with that tag, newest first, keyed by slugify( tag ) |
collections.taxonomies.<name>.terms | For each key listed in the taxonomies config key: every value of that front matter key, once, in its original spelling, sorted case-insensitively |
collections.taxonomies.<name>.byTerm[ slug ] | Documents with that value, newest first, keyed by slugify( term ) |
collections.global | The data files in _data/, nested by folder: _data/nav/main.json is collections.global.nav.main |
Drafts (unless --drafts), documents with excludeFromCollections: true, and the template of a paginated document are not in any collection. The pages that pagination generates are.
Pagination over collections.tags (or a taxonomy's terms) also produces pages for the tags carried by paginated documents, so every tag in the final collections.tags gets its page. Tags that only arrive through pagination data itself (the struct values merged into each page with size: 1) are not known at that point and may not get a page.
Taxonomies
tags is built in. To group documents by other front matter keys, list them in ssg-config.json:
json{
"taxonomies": [ "categories" ]
}
A document with categories: [ Guides, News ], or categories: Guides, then appears in collections.taxonomies.categories.byTerm.guides. A single value is one term and a list gives one term per entry; an empty value gives none, and entries that are empty or are themselves lists or mappings are skipped. When the first entry of the list is itself a list, that inner list is used instead ([ [ Guides, News ] ] reads as [ Guides, News ]). tags follow the same rules, except that for tags this inner-list case is handled only in a document's own front matter, not in folder defaults. collections.taxonomies always exists, empty when nothing is configured. Listing tags is allowed and gives the same terms as collections.tags. A page per term:
html<!---
title: Categories
permalink: /category/{{category}}/
pagination:
alias: category
data: collections.taxonomies.categories.terms
--->
Data files
Every .json, .yml, .yaml and .csv file under _data/ is loaded into collections.global, keyed by folder and file name without extension. Other files are ignored.
- JSON and YAML files hold any value. An empty YAML file is an empty struct.
- A CSV file becomes an array of structs: the first row is the header, each further row a struct keyed by the header names, with every value a string. Quoted fields may contain commas, line breaks and doubled quotes (
""). Blank lines at the end are ignored; a row with a different number of fields than the header fails the build. - A
.yml,.yamlor.csvfile with the same key as a.jsonfile, such as_data/team.jsonand_data/team.yml, is skipped: the JSON file is used and the build prints a warning naming both. - Two
.yml,.yamlor.csvfiles with the same key, such as_data/team.ymland_data/team.csv, fail the build naming both, as does a file that does not parse. - Two
.jsonfiles with the same key, such as_data/team.jsonand_data/team.backup.json(the key is the file name up to its first.), are both loaded and the one listed later by the file system wins, as in 1.0.