Jekyll has first class support for tags
and categories
in blog posts.
Tag feature basically consists of three abilities:
- a) adding tags to posts,
- b) displaying all tags, with posts count and
- c) browsing posts by tag.
Adding tags to posts
Tags for a post are defined in the post’s front matter using either the key tag
for a single entry or tags
for multiple entries.
Since Jekyll expects multiple items mapped to the key tags
,
it will automatically split a string entry if it contains whitespace.
For example, while front matter tag: classic hollywood
will be processed into a singular entity "classic hollywood"
,
front matter tags: classic hollywood
will be processed into an array of entries ["classic", "hollywood"]
.
Irrespective of the front matter key chosen(tag
or tags
),
Jekyll stores the metadata mapped to the plural key which is exposed to Liquid templates.
Displaying Tags
displaying tags on a post
displaying all tags in a site
Jekyll offers global array site.tags
which contains information on all the tags.
Each element is an array as follows: [0]
- tag name and [1]
- all posts for the tag.
示例如下:
- java(1)
- agent(1)
- instrumentation(1)
All tags registered in the current site are exposed to Liquid templates via site.tags
.
Iterating over site.tags
on a page will yield another array with two items,
where the first item is the name of the tag and the second item being an array of posts with that tag.
示例如下: