Can I exclude files in my project folders from my site?


#1

Sorry if this is a silly question, but I’m quite new to Jekyll, and haven’t yet got my head round some of the features.

It seems that every .md file in my project will be built and included in my static site. Can I do anything to stop some files being included at all in a specific output?

The reason I ask is because my first foray into Jekyll has a requirement to support single-sourced content, including multiple output sites from the same content, to support multiple product variants. Liquid allows us to define conditionally-included content, and to specify different configuration files for different builds, so different outputs can have content differences within an output page. For example, a paragraph may be included in the output for product variant A but may not apply to product variant B, although everything else on the page applies to both products.

Is there a way to stop a page from being included in one or more outputs at all, if nothing on that page applies to that product variant? I can figure out how to exclude it from the site navigation, so nothing on the site links directly to it, but if it’s present in the output at all, it’s still going to be included in any search results, and will also be available to anyone via the URL. This may be confusing and undesirable.

Do we need to do some pre- or post-processing, and manually remove the pages that don’t apply to this build, or is there a configurable way to tell Jekyll to exclude some files in the project structure from the build?

Thanks in anticipation


#2

In Jekyll’s _config.yml file you can exclude files/directories, which Jekyll will then ignore. See the config docs here for more info: http://jekyllrb.com/docs/configuration/

Exclude directories and/or files from the conversion. These exclusions are relative to the site’s source directory and cannot be outside the source directory.
exclude: [DIR, FILE, ...]


#3

Thank you! That’s exactly what I was looking for! I’m not quite sure why I didn’t find it when I looked. :slight_smile:


#4

on a side note, I have also found that if you prefix any folder or file with underscore, Jekyll ignores is, example: _pages