Open
Description
This issue provides an overview of intended (potentially breaking) changes for collections 2.0 release
Please comment if you disagree, feedback is welcome!
- BREAKING - Only store collections in
metadata.collections
. In 1.x for example a collection callednews
is also stored asmetalsmith.metadata().news
. This plugin should not pollute, and potentially overwrite, multiple other metadata keys - BREAKING - Store collection metadata as properties on the collection, instead of in the property
metadata
. This makes for cleaner access in templates, egcollections.news.title
instead ofcollections.news.metadata.title
, and is in line with how metadata is defined for files and build metadata. Might be safer in that case to have collections be an object withitems: Array<File>
property instead of an array. - Pushing the file objects (as references) in collections is problematic for adding previous/next references when a file is assigned multiple collections: which collection would the previous/next references then refer to? The first? The last? The current tests are lacking in this regard. But the file objects cannot be cloned as "collection items" because they will get out of sync with subsequent plugin transforms. The file objects need the reference to be on them to be accessible in templates. 3 paths to go:
- BREAKING - Remove support for multiple collections. All good without extra tests
- BREAKING - The
previous
andnext
references become objects with a key matching each collection assigned to the file, eg.next.tech
&next.hobby
. - BREAKING - The
previous
andnext
references are removed. Thecollection
key on the file becomes an object with a key matching each collection, whose value is[name:string, previous:[...File],next:[...File]]
. Layouts can then do:{{ collection.news.next.title }}
or when looping `{{# each collection }}{{#each this }}{{/each}}
- Allow specifying either
collection
orcollections
in file front-matter, but normalize it tocollection
as an array.
Anyhow it seems to increasingly make sense to map collections as:
{
name: 'my-collection',
items: [File, File, File],
...metadata
}
And to remap them on the file objects as collection
as:
{
name: 'my-collection',
...metadata
previous: [File, File],
next: [File, File]
}
Usage examples:
- Get the first collection (in nunjucks):
{{ collection | first }}
Metadata
Metadata
Assignees
Labels
No labels