Join James Williamson for an in-depth discussion in this video Tags and categories overview, part of Jekyll for Web Designers.
- By default, Jekyll organizes your posts by date, even publishing them to directories based on dates unless you change the default permalink styles. Chances are, you may want to organize your posts by subject matter, or categorize them in some more meaningful way. In Jekyll, we can do this by using categories and tags. Now unfortunately, there's not a lot of information about tags and categories in the documentation. You'll notice that I'm on the page right now referencing front matter, and if I scroll down, I see that in the Predefined Global Variables, we find categories in tags.
And first, you'll notice that category has two variables, category, singular, and a plural version, categories. So instead of placing posts inside of folders, you can specify one or more categories that the post belongs to. When the site is generated, the post will act as though it has been set with those categories normally. Categories, plurically, can be specified as a YAML list or as a comma-separated string. Okay, so what about tags? Well, you'll notice it defines tags as being similar to categories, one or more multiple tags can be added to a post.
Also like categories, tags can be specified as a YAML list, or as a comma-separated string. Okay, so essentially these are variables that can be assigned to individual posts to represent them in some meaningful way. Really, the only difference between the two of them is that categories can be reflected in the permalinks of your posts. So for example, if I go back up and take a look at the Permalinks section, you'll notice that in the default style for permalinks, categories is listed first. So it will arrange them in directories by categories first, then your month, date, and title.
That is, of course, if you're using categories. So categories allow us to reflect them in the permalinks of the posts themselves, so they help us with the organization of our site if we use them. They can also be hierarchical in nature, but that means, for example, if you came up with a category of food you could come up with a category of cupcakes, which is sort of a subcategory to food. Tags, on the other hand, are flat. They're non-hierarchical in nature, and they're not reflected in permalinks. They're just a way to organize posts by subject matter or content.
Now I really wish there was more information on tags and categories in the documentation. When I was learning Jekyll, I had to go outside of Jekyll's documentation, and really see how people were using categories and tags in their sites in order to get a better understanding of them. And actually, tags and categories are kind of a good news, bad news thing inside of Jekyll. The good news is that you can choose between using tags and categories to help you organize your posts. The bad news is that Jekyll really doesn't have any automated means of generating archive pages or content pages based off of those tags and categories.
That means that you're going to have to build those yourself, which is what we're going to do as we create our archives page in this chapter.
- Installing Jekyll
- Setting configuration options
- Building page templates and navigation
- Adding metadata and content with Jekyll
- Creating a blog index with dates, post excerpts, and pagination
- Writing posts and pages using Markdown
- Creating a blog archive with tags
- Deploying Jekyll websites
- Uploading to GitHub