Jekyll Collections Versus Posts
Differences
These are the main differences between Collections and posts.
Categories
A post in a subdirectory structure automatically gets subdirectories names as its categories.
A collection does not have categories by default.
Filenames
Post filenames must be in the format YYYY-MM-DD-title.<markup>
which
assigns the post date, used to sort posts by creation date.
Collection filenames doesn’t need any special format in filenames,
they get the date
from the file creation date.
date
variable. (i.e. date: 2016-06-08
)Directories
Posts have the restriction of being only recognized if they are located
under a _posts
folder.
This restriction won’t be removed as it is being kept to not break
previous versions.
Collections can be located directly in any directory of the collection folder.
Dates
This is one of the most important difference between them.
Posts were originally aimed for blogs, so the date
is a central concept
that is also displayed in its filename, they are not likely to get updated
after published.
βββ _posts
βββ 2016-11-19-why-every-developer-should-use-emacs.md
βββ 2016-06-20-open-source-in-governments.md
- Beside collections have a
date
property, this is not an important concept as it is in posts, a clear structure is needed to locate each file quickly when needed to update or add data to them.
βββ _my_collection
βββ open-source-in-governments.md
βββ why-every-developer-should-use-emacs.md
Summary
Considering publishing a list of books with both approaches:
a list of standard posts in
books
folder.a collection in
_books
folder, with the following configuration:In
/_config.yml
:collections: books: output: true
/_books
,
needed to let Jekyll handle the directory as a collection.This is how they basically compare:
# | Collection | Post |
---|---|---|
Directories | /_books/science/ | /books/science/_posts/ |
File | item.md | 2016-06-10-item.md |
{{ page.categories }} | ["books", "science"] | |
{{ page.date }} | from file creation date:2016-07-11 23:03:59 | | from filename: 2016-06-10 |
Document access | site.books site.collections | site.categories.science ,site.collections ,site.categories.books or site.posts | |
File handling the URL | http://example.com/books/science | /books.html with permalink: "/books/science" or /books/science/index.md |
Choosing between Collections and Posts
Features of Collections:
- a cleaner directory/subdirectories structure without
_posts
folder in each nested level - cleaner filenames without mandatory dates.
- In a hierarchical subdirectoy structure, categories can be simulated
processing the
path
property of each file. - Collection filenames put more emphasis in its
title
, not thedate
.
Features of Posts:
- Posts were introduced in Jekyll before collections, so they are widely adopted and with more plugins available.
- Posts filenames put more emphasis in
dates
, not thetitles
. - when using nested directories, creating each subdirectory index is straightforward.
References
- Jekyll Collections docs https://jekyllrb.com/docs/collections/
- Jekyll Posts docs https://jekyllrb.com/docs/posts/
- Jekyll Collections Versus Posts
- Understanding How Collections WorkJune 11, 2016
Articles
Except as otherwise noted, the content of this page is licensed under CC BY-NC-ND 4.0 . Terms and Policy.
Powered by SimpleIT Hugo Theme
·