How Jekyll knows what files are posts/pages/etc?

In the Front Matter Defaults documentation, there is written:

Since the path is set as an empty string, it will apply to all files in your project. You probably don’t want to set a layout on every file in your project - like css files, for example - so you can also specify a type value under the scope key.

So we specify a file type.

Later on, we put the following in our _config.yml:

defaults:
  [...]
  -
    scope:
      path: "projects"
      type: "pages" # previously `page` in Jekyll 2.2.
    values:
      layout: "project" # overrides previous default layout
      author: "Mr. Hyde"

So we apply this default to file of type pages.

But what is a “page” to begin with? How does a file acquire the type of “page”?

I thought a “page” was a HTML or MD file residing under _pages (see the step-by-step tutorial).

But that is not the case, since in this case they reside under “projects”.

how does jekyll tell which file in “projects” is of a “page” type?

Any html files that exist in the projects/ folder will use the project layout, if it exists.

So any HTML file under projects will use the project layout.

So a page is any HTML file. So what is a post? Is it not a HTML also?

There is even more confusion as the Front Matter doc specify a new, undefined, type: “document”

Starting from version 3.5.0, using none in a post/document will produce a file without using a layout file regardless of front matter defaults.

1 Like

Hello @filomena,
Jekyll assigns type based on whether it is part of a collection and whether it contains front matter (even if empty front matter).
Files with front matter inside a collection are of type akin to the collection. i.e., inside collection _posts, the file is of type posts, but if inside collection _projects, then the type is projects, etc. Files with front matter but not in a collection is of type pages. Confusion arises when a user creates a collection out of _pages. Jekyll now considers both as pages.
Files without front matter anywhere in the site has a null type.

1 Like

That’s clear. THanks