Jekyll Files and Folders An In-Depth Look

When you first create a Jekyll site, you'll notice a handful of files and folders right away. Some have names you might recognize, like a configuration file, while others, with their leading underscores, might seem a bit mysterious. It's a common feeling, but each of these components plays a vital role in building your static website. This article will take a close look at every key file and folder, explaining its purpose in a way that's easy to understand. By the end, you'll know exactly what everything does, which will give you the confidence to start building and customizing your GitHub Pages site. This knowledge is the foundation for creating a clean, organized, and scalable project from the very beginning.

Table of Contents

Jekyll’s power lies in its simplicity and its predictable structure. The system is designed to be smart about how it processes your files. For example, it knows that a file in the _posts directory is a blog post and will treat it differently than a file in the root directory. It also knows that files starting with an underscore are special and should not be copied to the final website as-is. This predictable structure is not a bug; it's a feature. It streamlines the entire process of converting your source files into a live, static website, especially when you're relying on a service like GitHub Pages to do the heavy lifting for you.


The Core Configuration Files

_config.yml The Master Control

The _config.yml file is the single most important file in your Jekyll project. This is where you set up all the global parameters for your site. You can define the site’s title, a short description, the author’s name, and a base URL. It's also where you can configure how URLs (permalinks) for your posts should be structured, which is a great feature for SEO. Additionally, you use this file to specify which plugins Jekyll should use and which folders or files to ignore during the build process. A well-maintained _config.yml file is the cornerstone of a healthy Jekyll site, as it ensures all your settings are in one central, easy-to-find location.

The file is written in YAML, which is a human-readable data serialization format. Its simple structure of key-value pairs makes it easy to understand and edit. For instance, to set your site’s title, you would simply write title: "My Awesome Site". Because this file affects the entire website, you should always double-check your changes after editing it to make sure everything is working as expected. Think of it as the project’s main instruction manual; it tells Jekyll exactly how to build your site.

Gemfile and Gemfile.lock for Dependencies

Jekyll is a Ruby gem, and to make sure your project can be built consistently, you need to manage its dependencies. This is the job of the Gemfile and Gemfile.lock. The Gemfile is where you list all the Ruby gems your project relies on, including Jekyll itself and any plugins you might be using. For example, you might add a gem for creating a sitemap or for handling comments. When you run the bundle install command, Ruby reads this file and downloads all the necessary gems.

The Gemfile.lock file is then automatically generated. Its purpose is to record the exact versions of every gem that was installed. This is incredibly useful for ensuring your site builds the same way on your local machine and on the GitHub Pages server. You should never edit Gemfile.lock manually; it is a file that is managed automatically by Bundler, the Ruby gem manager. By including both these files in your repository, you guarantee that anyone who clones your project will be able to build it correctly without any version conflicts.


Your Content in Posts and Pages

_posts for Your Blog Articles

The _posts directory is where Jekyll finds and processes your blog posts. Every file in this directory must be a Markdown file with a very specific naming convention: YYYY-MM-DD-your-post-title.md. The date part is crucial, as it allows Jekyll to automatically sort your posts chronologically. The title part, with words separated by hyphens, is used to create a clean URL slug. This simple convention is what makes it so easy to manage a blog with dozens or even hundreds of articles. You simply create a new file in this folder, and Jekyll knows exactly what to do with it.

Inside each post file, you must include a block of YAML front matter at the top. This is a section enclosed in three hyphens (---). The front matter is where you define metadata like the post's title, author, date, and which layout to use. You can also add custom metadata here, like tags or categories, which can then be used to organize and display your content on your site. This structured approach to content is one of the key reasons Jekyll is so effective for blogging.

Creating Pages The Easy Way

Not all content is a blog post. For static content like an About page, a Contact page, or a custom landing page, you create files or folders directly in the root of your project. For example, a file named about.md will become your /about/ page. A file named contact.html will become your /contact.html page. This straightforward system means the structure of your files directly reflects the URL structure of your website, making it very intuitive. You can also create subdirectories to organize your pages, such as /docs/getting-started.md, which will create the page at /docs/getting-started/.

This flexibility allows you to build a wide variety of static websites, not just blogs. You can mix and match Markdown and HTML files depending on your needs. For instance, you might use Markdown for content-heavy pages because it's easy to write, but use a pure HTML file for a complex contact form. This simple, file-based approach to page creation is what makes Jekyll so accessible for beginners and powerful for more advanced users.


The Design Folders for Your Site

_layouts and the Structure of Your Site

The **_layouts** directory is the home for all your website’s HTML templates. These layouts define the overall look and feel of your pages. You might have a default.html layout that includes the header, footer, and navigation bar, and then more specific layouts like post.html or page.html that build upon the default layout. This system of nested layouts allows you to create a consistent design across your entire site without repeating code. When you specify a layout in your page's front matter, Jekyll takes your content and inserts it into the correct template, generating the final HTML file.

_includes for Reusable Code Blocks

The **_includes** folder is where you put small, reusable snippets of code. Think of things like a sidebar widget, a social media icon list, or a complex footer. Instead of copying and pasting the same HTML code into multiple layouts or pages, you can put it in a file inside _includes and then use a simple Liquid tag to include it wherever you need it. This keeps your code DRY (Don't Repeat Yourself) and makes your site much easier to maintain. If you need to make a change to a common element, you only have to edit it in one place, and the change will be reflected everywhere.

_sass for Advanced Styling

If you're using a CSS preprocessor like Sass, the **_sass** directory is where your source files go. Jekyll is built with Sass support, so it will automatically process any .scss or .sass files in this folder and compile them into a single CSS file. This allows you to write more modular and maintainable stylesheets using variables, mixins, and nested rules. The final, compiled CSS file will then be placed in a directory like /assets/css/, ready to be used by your layouts.


The Output and the Ignored

When you run the Jekyll build command, all of these pieces come together to create your final website in the **_site** directory. This is the output folder that contains all the static files you need to deploy. It’s crucial to remember that this folder should never be edited manually. It's a temporary directory that is recreated every time you build your site. Finally, files and folders that you want Jekyll to ignore, such as your node_modules directory or a draft folder, can be specified in your _config.yml or with a leading underscore, like _drafts. This helps keep your project clean and prevents unnecessary files from being included in your final website.

Comments