Collections
Group pages for indexes, sidebars, and feeds.
Collections group matching Markdown files so templates can loop over them.
Default posts collection
collections: {
posts: {
pattern: 'blog/**/*.md',
sortBy: 'date',
reverse: true,
},
},
In a template:
{% for post in collections.posts %}
<a href="{{ post.url }}">{{ post.data.title }}</a>
{% endfor %}
Custom collections
Add any named collection. For example, documentation pages sorted by an order frontmatter field:
collections: {
docs: {
pattern: 'docs/**/*.md',
sortBy: 'order',
},
},
---
title: Getting started
layout: docs
order: 20
---
{% for doc in collections.docs %}
<a href="{{ doc.url }}">{{ doc.data.title }}</a>
{% endfor %}
Sort behavior
sortBy: 'date'sorts chronologically; newest-first unlessreverse: false- Other
sortByfields use string comparison; setreverse: trueonly when you want descending order - Prefer spaced numeric orders (
10,20,30) when sorting byorder— string sort puts100before20
Collection item shape
Each item exposes:
url— page URLpath— source path relative to contentdata— frontmatter fields- rendered content available depending on context