Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jekyll: collections vs data file

Tags:

ruby

jekyll

What are the advantages of using collections than data files? They seem to be able to achieve the same purpose. Plus usually we have data files of items (e.g. JSON, csv), then I have to transform them if using collections. The differentiation between posts vs collections/datafile is clearer but I am confused when should I use collections vs data files.

like image 219
cccfran Avatar asked Sep 13 '19 00:09

cccfran


1 Answers

TL;DR:

  • Collection—Will have its own page, URLs, and possibly an index page.
  • Data—Will not have its own page, but will be referenced to on other pages within the site.

Longer answer:

In practice, collections and data are very similar.

A good way to think of the difference is: collections generally have their own page, data are supplemental information that you want to load dynamically or reuse on more than one page.

So for example, I manage a website that includes many user testimonials that are referenced on specific project pages. Testimonials do not have their own page, and there's no index of testimonials. So I use a data yaml testimonials.yml file for those.

The site has projects (it's a professional portfolio), and each project has its own page, URL, etc. In this case, I define a collection for my projects.

Jekyll blog posts are basically just a collection that's pre-defined.

like image 111
bodacious Avatar answered Sep 28 '22 06:09

bodacious