jekylljekyll-theme

Jekyll definition for site or page variables?


In many situations, when using Jekyll, should one use site.pages or page.title ect?

In official doc, there are meanings about those variables. However, after reading I'm still confused.

Eg:

I'm still wondering what's the meaning of "all pages": all pages in root directory of my project? Or all pages in any depth of my project? Besides what's the definition of pages?

What is the definition position in code for site.pages?

site: Site wide information + configuration settings from _config.yml.

What is the difference between "site wide information", or the definition positions for these "site wide information"?


Solution

  • At the basic level, there are 5 kinds of data types in Jekyll.

    The first two in bold can be seen as content-type primitives. Jekyll uses front matter — key-value pairs enclosed by a pair of three consecutive dashes. e.g:

    ---
    foo: bar
    ---
    

    — to determine whether a given content-file needs to be processed by Jekyll.

    If the file doesn't contain front matter at the very beginning, it is simply copied from source to destination as is without any change. Such a file is known as a Static file.

    Otherwise, the contents of the file are sent to be processed which ultimately results in a HTML file. Such files are either Pages or Documents. The difference between these two are whether the files are part of a Collection or not.

    A Collection is a set of files contained within a special directory. The directory name starts with an underscore and has to be explicitly listed (without the leading underscore) in the config file for it to be seen as a Collection directory. Files (within a collection) that start their content with front matter are seen as Documents. Those that don't have front matter are simply static files.


    Simply put, site.pages comprises of all those files that contain front matter at the very beginning but are themselves not part of any collection. Have such an about.md at the root of your project directory? It is a Page.

    Documents inside a collection are accessed via the collection. Therefore, if your site has a Collection labelled movies and couple of files within the directory _movies, then they can be accessed via site.movies


    posts are a pre-defined collection and handled with a special status. Individual posts need not contain front matter and they're still accessible via site.posts