What's the difference between categories and tags in Jekyll?

GithubBlogsJekyll

Github Problem Overview


Both of their elements can be accessed by for..in, and the way of adding categories and tags are the same. So, what's the difference between categories and tags in Jekyll?

Github Solutions


Solution 1 - Github

It seems to me that the only important difference is that categories can be used in the post url - a post inside the "beer" and "food" categories, by default, will have this url:

/food/beer/2008/09/09/foo-bar.html

Instead of this one:

/2008/09/09/foo-bar.html

See the post tests for details

Tags have no influence in the urls, at least according to their tests.

Solution 2 - Github

From the documentation:

  • 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 had been set with these categories normally. Categories (plural key) can be specified as a YAML list or a space-separated string.

  • Similar to categories, one or multiple tags can be added to a post. Also like categories, tags can be specified as a YAML list or a space-separated string.

That only suggests similarities; it doesn't really explain the differences between categories and tags. This video tutorial suggests that:

> the only difference between the two of them is that categories can be reflected in the permalinks of your posts.

It goes on to explain that

> 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 that

> Jekyll really doesn't have any automated means of generating archive pages or content pages based off of those tags and categories.

Support for that kind of thing would be implemented in the theme you're using or you could do it yourself.

Solution 3 - Github

The v4.2 documentation has an updated answer.

> The hallmark difference between categories and tags is that categories of a post may be incorporated into the generated URL for the post, while tags cannot be. > > Therefore, depending on whether front matter has category: classic hollywood, or categories: classic hollywood, the example post above would have the URL as either movies/horror/classic%20hollywood/2019/05/21/bride-of-chucky.html or movies/horror/classic/hollywood/2019/05/21/bride-of-chucky.html respectively.

Both categories and tags are made available to Liquid templates and can be iterated over.

Both categories and tags can be defined in a post's front matter. Categories can also be defined by a post’s file path:

> Any directory above _post will be read-in as a category. For example, if a post is at path movies/horror/_posts/2019-05-21-bride-of-chucky.markdown, then movies and horror are automatically registered as categories for that post. > > When the post also has front matter defining categories, they just get added to the existing list if not present already.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionjiyinyiyongView Question on Stackoverflow
Solution 1 - GithubkikitoView Answer on Stackoverflow
Solution 2 - GithubstarfryView Answer on Stackoverflow
Solution 3 - GithubIan Greenleaf YoungView Answer on Stackoverflow