Inside Jekyll A Comprehensive Guide to its Directory Structure


If you want to master Jekyll and build a professional website on GitHub Pages, a deep understanding of its directory structure is essential. It's the blueprint that dictates how your website is built. This article provides a comprehensive tour of every significant file and folder in a Jekyll project. We will go beyond the basics to explain the function of each component, from the core configuration files to the advanced data and styling directories. By the end of this guide, you'll have a complete mental map of a Jekyll project, giving you the confidence to manage, expand, and troubleshoot your site effectively. This knowledge is what turns a beginner into a skilled Jekyll user.

Table of Contents

Jekyll’s architecture is built on a "convention over configuration" philosophy. This means that by placing files in specific folders, you're telling Jekyll how to process them. This system automates much of the website creation process and provides a logical framework for your project. The clear separation between content, design, and configuration is the key to building a scalable and maintainable website. Let's start our tour at the root of the project, where the most important files reside.


The Root The Project's Command Center

_config.yml The Master Settings File

At the root of your project, the _config.yml file is your site's master control panel. This single file is where you define all the global settings that apply to your entire website. It’s where you set your site’s title, a short description, and its base URL. You also use it to configure important features like permalinks, which control the URL structure of your posts and pages. For example, you can set a permalink to /blog/:title/ to ensure all your post URLs are consistent. This file is also where you specify which plugins to use and which files or directories to ignore during the build process. A well-organized and well-documented _config.yml file is the foundation of a healthy Jekyll project.

Gemfile and Gemfile.lock Managing Dependencies

While not a core part of Jekyll's directory structure, the Gemfile and Gemfile.lock are critical for any Jekyll project. The Gemfile is where you list all the Ruby gems your site depends on, including Jekyll itself and any plugins you might use. The Gemfile.lock file is automatically generated and records the exact versions of these gems. This is crucial for ensuring that your site builds consistently on any machine, including the GitHub Pages servers. By including both these files in your repository, you guarantee that your project is reproducible and free from version-related conflicts.


The Underlined Directories The Core Components

_posts The Blog Engine

The _posts directory is the dedicated home for all your blog posts and articles. Every file in this folder must follow a strict naming convention: YYYY-MM-DD-your-post-title.md. This format is what allows Jekyll to automatically sort your posts chronologically and generate a clean URL. Inside each post file, you include YAML front matter at the top to provide metadata like the post's title, author, and the layout it should use. This structured approach makes it easy to manage a blog of any size and is a key reason Jekyll is so popular for blogging.

_layouts and _includes The Design System

Jekyll’s design system is built on two primary directories: _layouts and _includes. The _layouts folder contains your full HTML templates. A layout is a blueprint for a page, defining its overall structure, from the header and navigation to the footer. You can create a hierarchy of layouts, such as a default.html layout that other layouts like post.html and page.html inherit from. This system prevents code duplication and makes site-wide design changes incredibly easy. The _includes folder is for smaller, reusable HTML snippets. Things like a social media block or a navigation menu can be saved as a file here and then inserted into any layout using a simple Liquid tag. This makes your code modular and much easier to maintain.

How to use an include

To use an include, you would create a file like _includes/footer.html and then add {% include footer.html %} to your layout file. Jekyll will automatically insert the content of your footer file right there when it builds the site.

_data Separating Content from Code

For more advanced projects, the _data directory is a powerful tool. It's where you store data in YAML, JSON, or CSV files that can be accessed and used anywhere on your site. For example, you could have a file named _data/team.yml containing a list of your team members. You can then use a Liquid loop in a layout to dynamically generate a team page. This is a great way to separate your content from your templates, making it easier to manage data that is reused across your site, such as navigation links, pricing tables, or testimonials.

.
├── _data/
│   ├── navigation.yml
│   └── team.yml
├── _layouts/
│   └── default.html
└── ...

_sass for Advanced Styling

If you're a designer or a developer who loves using a CSS preprocessor, the _sass directory is for you. This folder is where you place your Sass source files. Jekyll has built-in support for Sass, so it will automatically process these files and compile them into a single CSS file. This allows you to write more modular and organized stylesheets using features like variables and mixins, making your design system more robust and easier to manage.


The Final Stage The Static Output

After Jekyll processes all these files and folders, it places the final, static website inside the _site directory. This is the complete, ready-to-publish website that you can deploy to GitHub Pages. It's a key distinction that the _site folder is an output directory, not a source directory. You should never edit any files inside it directly, as it gets completely erased and rebuilt every time you run the build command. To prevent this folder from being committed to your Git repository, it's a critical best practice to add _site/ to your .gitignore file.

Comments