Navigating the Jekyll Directory The Key to Mastering GitHub Pages

If you're using Jekyll to build a website on GitHub Pages, the directory structure is your most important tool. It’s not just a random collection of files and folders; it's a logical system that tells Jekyll exactly what to do. Learning this structure is like learning the blueprint of a house. Once you understand where the foundation is, where the walls go, and what the purpose of each room is, you can build and expand it with confidence. This guide will help you navigate your Jekyll project folder by folder, so you can stop guessing and start creating. A clear understanding of this system is the key to building a clean, scalable, and easy-to-manage website that performs well on GitHub Pages.

Table of Contents

Mastering the Jekyll File System

Jekyll's design is all about convention. This means the names of certain folders and the placement of certain files are not just suggestions—they are expectations. Jekyll looks for a folder named _posts to find your blog articles and for a folder named _layouts to find your templates. This predictable structure is what allows Jekyll to automate much of the website creation process. By working with this system, rather than against it, you can take full advantage of Jekyll’s power and build your site much faster. Let's start with the most important part of your project: the root directory.


The Root Directory Your Sites Home

The Importance of _config.yml

At the very top level of your project is the root directory. Here, you'll find a handful of critical files. The most important of these is **_config.yml**. This file is your website's main settings panel. It’s where you define site-wide information like the title, description, and base URL. It's also where you can set up how Jekyll should generate your pages, such as the URL format for your blog posts. Because these settings are global, any changes you make in this file will affect your entire website. Keeping this file organized and well-documented is crucial for long-term project health. Think of it as the main control center for your website, dictating how everything else should work.

You can also use _config.yml to specify which files or directories Jekyll should ignore during the build process. For example, you might have a _drafts folder for unfinished posts that you don't want to publish yet. By telling Jekyll to ignore this folder, you can keep your draft content in the same project without it being published live. This file is the first thing Jekyll reads when it starts building your site, so it's essential for getting your project off on the right foot.

Your Content Posts and Pages

The root directory is also where your primary content lives. This is a key distinction in Jekyll. Your main website pages, such as an "About" page or a "Contact" page, are created by simply placing a Markdown or HTML file directly in the root directory. For example, a file named about.md will automatically become the /about/ page on your website. This system is very intuitive, as the file structure directly mirrors the website's URL structure. It makes it easy to find and edit the content for specific pages.

In contrast, your blog posts are stored in a dedicated folder named **_posts**. This is the key difference between posts and pages. Jekyll processes posts differently by using the date in their filename to sort them. This separation of content into pages for static content and posts for chronological content is a fundamental concept in Jekyll and helps keep your project well-structured and easy to manage. When you know where to put your content, the rest of the process becomes a breeze.


Inside the Special Folders

_layouts and the Look of Your Site

To give your website a consistent look and feel, Jekyll uses templates stored in the **_layouts** folder. A layout is an HTML file that acts as a blueprint for your pages. For example, you might have a default.html layout that includes the header, navigation, and footer. Then, you could have a post.html layout that uses the default layout but adds specific styling for a blog post. By specifying which layout a page or post should use in its YAML front matter, you can apply a consistent design without having to repeat the same HTML code on every file. This makes your site much easier to maintain and update.

.
├── _layouts/
│   ├── default.html
│   └── post.html
├── _posts/
│   └── 2024-01-01-hello-world.md  <-- This post uses a layout
└── about.md                     <-- This page uses a layout

This templating system is one of Jekyll’s most powerful features. It allows you to separate your content from your presentation. If you ever want to change the look of your entire website, you only need to edit a handful of layout files, and the changes will be automatically applied to all the pages and posts that use them.

_includes for Efficiency

The **_includes** folder is where you put small, reusable bits of HTML code. If you have a piece of code that you want to use in multiple layouts or pages—like a footer, a navigation bar, or a social media icon block—you can save it as a file in the _includes directory. Then, using a simple Liquid tag like {% include footer.html %}, you can insert that code wherever you need it. This keeps your code clean and manageable, following the "Don't Repeat Yourself" (DRY) principle. If you need to make a change, you only have to edit the file in the _includes folder, and it will update everywhere it’s used.

Managing Assets Like a Pro

For files that Jekyll doesn’t need to process, such as your images, CSS files, and JavaScript files, you should store them in a dedicated folder. A common practice is to create a folder called **assets** at the root of your project. Inside this folder, you can create subdirectories like css, js, and images. Jekyll will simply copy these files to the final _site directory, keeping their folder structure intact. This means you can link to them in your pages and layouts using a simple relative path like /assets/css/style.css. This method keeps your project organized and prevents clutter in the root directory.


What to Do With the _site Folder

Finally, when you build your Jekyll site, all these files and folders are compiled into a final, static website inside the **_site** directory. This folder is the output, and it contains all the HTML, CSS, and other files that a web browser needs to display your site. It is extremely important that you do not manually edit any files within this folder. Every time you run the build command, the _site folder is completely erased and rebuilt from scratch. The _site folder is what gets deployed to GitHub Pages, but you should never commit it to your Git repository. It's best to add _site/ to your .gitignore file to prevent it from being accidentally uploaded.

Comments