Tags provide another means of navigation for your content. Unlike the table of contents, tags can show the content in a variety of arrangements and groupings. Implementing tags in this Jekyll theme is somewhat of a manual process.

Add a tag to a page

You can add tags to pages by adding tags in the frontmatter with values inside brackets, like this:

---
title: 5.0 Release Notes
permalink: release_notes_5_0.html
tags: [formatting, single_sourcing]
---

Tags overview

To prevent tags from getting out of control and inconsistent, first make sure the tag appears in the _data/tags.yml file. If it’s not there, the tag you add to a page won’t be read. I added this check just to make sure I’m using the same tags consistently and not adding new tags that don’t have tag archive pages.

Additionally, you must create a tag archive page similar to the other pages named tag_{tagname}.html folder. This theme doesn’t auto-create tag archive pages.

For simplicity, make all your tags single words (connect them with hyphens if necessary).

Setting up tags

Tags have a few components.

  1. In the _data/tags.yml file, add the tag names you want to allow. For example:

    allowed-tags:
      - getting_started
      - overview
      - formatting
      - publishing
      - single_sourcing
      - special_layouts
      - content types
    
  2. Create a tag archive file for each tag in your tags_doc.yml list. Name the file following the same pattern in the tags folder, like this: tag_collaboration.html.

    Each tag archive file needs only this:

    ---
    title: "Collaboration pages"
    tagName: collaboration
    search: exclude
    permalink: tag_collaboration.html
    sidebar: mydoc_sidebar
    ---
    {% include taglogic.html %}
    
  3. Change the title, tagName, and permalink values to be specific to the tag name you just created.

    By default, the _layouts/page.html file will look for any tags on a page and insert them at the bottom of the page using this code:

<div class="tags">
{% if page.tags != null %}
<b>Tags: </b>
{% assign projectTags = site.data.tags.allowed-tags %}
{% for tag in page.tags %}
{% if projectTags contains tag %}
<a href="{{ "tag_" | append: tag | append: ".html" }}" class="btn btn-default navbar-btn cursorNorm" role="button">{{page.tagName}}{{tag}}</a>
{% endif %}
{% endfor %}
{% endif %}
</div>

Because this code appears on the _layouts/page.html file by default, you don’t need to do anything in your page to get the tags to appear. However, if you want to alter the placement or change the button color, you can do so within the _includes/taglogic.html file.

You can change the button color by changing the class on the button from btn-info to one of the other button classes bootstrap provides. See [Labels][mydoc_labels] for more options on button class names.

Retrieving pages for a specific tag

If you want to retrieve pages outside of a particular tag_archive page, you could use this code:

Getting started pages:
<ul>
{% for page in site.pages %}
{% for tag in page.tags %}
{% if tag == "getting_started" %}
<li><a href="{{page.url | remove: "/" }}">{{page.title}}</a></li>
{% endif %}
{% endfor %}
{% endfor %}
</ul>

Here’s how that code renders:

Getting started pages:

If you want to sort the pages alphabetically, you have to apply a sort filter:


Getting started pages:
<ul>
{% assign sorted_pages = (site.pages | sort: 'title') %}
{% for page in sorted_pages %}
{% for tag in page.tags %}
{% if tag == "getting_started" %}
<li><a href="{{page.url | remove: "/" }}">{{page.title}}</a></li>
{% endif %}
{% endfor %}
{% endfor %}
</ul>

Here’s how that code renders:

Getting started pages:

Efficiency

Although the tag approach here uses for loops, these are somewhat inefficient on a large site. Most of my tech doc projects don’t have hundreds of pages (like my blog does). If your project does have hundreds of pages, this for loop approach with tags is going to slow down your build times.

Without the ability to access pages inside a universal namespace with the page type, there aren’t many workarounds here for faster looping.

With posts (instead of pages), since you can access just the posts inside posts.tag.tagname, you can be a lot more efficient with the looping.

Still, if the build times are getting long (e.g., 1 or 2 minutes per build), look into reducing the number of for loops on your site.

Empty tags?

If your page shows “tags:” at the bottom without any value, it could mean a couple of things:

  • You’re using a tag that isn’t specified in your allowed tags list in your tags.yml file.
  • You have an empty tags: [] property in your frontmatter.

If you don’t want tags to appear at all on your page, remove the tags property from your frontmatter.

Remembering the right tags

Since you may have many tags and find it difficult to remember what tags are allowed, I recommend creating a template that prepopulates all your frontmatter with all possible tags. Then just remove the tags that don’t apply.

See [WebStorm Text Editor][mydoc_webstorm_text_editor] for tips on creating file templates in WebStorm.

orzh-introduction

X-WAF-README

nginx-lua-module-zh-wiki

orange_about

agentzh-nginx-guide-01

pra_flame_how

orzh-introduction

X-WAF-README

nginx-lua-module-zh-wiki

orange_about

titlepage

tocpage

p1_landing_page

p1_sample1

p1_sample2

p1_sample3

p1_sample4

p1_sample5

p1_sample6

p1_sample7

titlepage

tocpage

p2_landing_page

p2_sample1

p2_sample2

p2_sample3

p2_sample4

p2_sample5

p2_sample6

p2_sample7

p2_sample8

p2_sample9

p2_sample10

p2_sample11

p2_sample12

p2_sample13

p2_sample14

titlepage

tocpage

p1_landing_page

p1_sample1

p1_sample2

p1_sample3

p1_sample4

p1_sample5

p1_sample6

p1_sample7

titlepage

tocpage

X-WAF-README

xwaf_installation

xwaf_depoly

xwaf_README

xwaf_advanced_readme

xwaf_getting_started

xwaf_faqs_readme

xwaf_roadmap

titlepage

tocpage

nginx-lua-module-zh-wiki

titlepage

tocpage

orange_api_server

orange_build_plugin

orange_dashboard_usage

orange_README

orange_basic_auth

orange_basic_info

orange_divide

orange_key_auth

orange_monitor

orange_rate_limiting

orange_redirect

orange_rewrite

orange_stat

orange_waf

orange_condition

orange_expression

orange_extraction

orange_extractor

orange_handle

orange_judge

orange_rule

orange_about

orange_contributing

orange_issues

orange_usages

titlepage

tocpage

add_new_lua_api

cosocket

get_req_body

get_url_param

helloworld

how_request_http

inline_var

install

install_on_centos

install_on_ubuntu

install_on_windows

install_osx

log_response

outtest

response

safe_sql

share_var

simple_api

sub_request

work_with_location

array_size

break

brief

build_env

call_user_func_array

capture

class

control_structrues

dot_diff

dummy_var

FFI

file

for

function_before_use

function_define

function_descrip

function_parameter

function_result

if_else

local

main

math_library

metatable

module_is_evil

module

not_nill

not_use_lib

not_use_module

object_oriented

operator

re

repeat

string_library

table_library

time_date_function

what_jit

while

pra_flame_how

pra_flame_install

pra_flame_what

pra_flame_when

pra_ngx_lua_allow_deny

pra_ngx_lua_block_io

pra_ngx_lua_cache

pra_ngx_lua_capture

pra_ngx_lua_continue_after_eof

pra_ngx_lua_debug

pra_ngx_lua_ffi

pra_ngx_lua_hot_load

pra_ngx_lua_how_one_instance_time

pra_ngx_lua_how_use_third_lib

pra_ngx_lua_keepalive

pra_ngx_lua_log

pra_ngx_lua_lua-limit

pra_ngx_lua_lua_opt

pra_ngx_lua_lua-variable-scope

pra_ngx_lua_on_abort

pra_ngx_lua_phase

pra_ngx_lua_resolve_the_domain_name

pra_ngx_lua_shared_get_keys

pra_ngx_lua_sleep

pra_ngx_lua_timer

pra_ngx_lua_use_case

pra_ngx_lua_whats_cosocket

pra_redis_auth_connect

pra_redis_dynamic_redis_module_method

pra_redis_out_package

pra_redis_pipeline

pra_redis_pub_sub_package

pra_redis_script

pra_redis_select-keeplive

pra_postgres_health_check

pra_postgres_how_to_use

pra_postgres_not_support_transaction

pra_postgres_sql_inject

pra_postgres_timeout

pra_nginx_balancer

pra_nginx_co-work_of_location

pra_nginx_if_is_evil

pra_nginx_match_uri

pra_nginx_nginx_brief

pra_nginx_nginx_local_pcre

pra_nginx_nginx_log

pra_nginx_nginx

pra_nginx_pitfalls_and_common_mistakes

pra_nginx_reverse_proxy

pra_nginx_static_file

titlepage

tocpage

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_scan_port

candylab_common_sites_log_system

candylab_graylog_clickhouse

candylab_clickhouse_basic

candylab_logs_and_gateway

candylab_sec_system_arch

candylab_logs_dsl_waf

candylab_opensock_list

candylab_opensock_practice

candylab_opensock_email

candylab_base_on_openresty_waf

candylab_dsl_waf

candylab_honeypot_system

candylab_monitor_redis

candylab_threat_replay

candylab_pcap_monitor

candylab_monitor_website

candylab_openrestyplus_waf

candylab_windows_bigdata

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

candylab_clickhouse_basic

titlepage

tocpage

agentzh-nginx-guide-01

agentzh-nginx-guide-02

agentzh-nginx-guide-03

agentzh-nginx-guide-04

agentzh-nginx-guide-05

agentzh-nginx-guide-06

agentzh-nginx-guide-07

agentzh-nginx-guide-08

mydoc_hyperlinks.html#automatedlinks

mydoc_hyperlinks.html#bookmarklinks

mydoc_pages.html#someIdTag

news

nginx-lua-module-zh-wiki

nginx-development-guide-zh

orange_about

X-WAF-README

pra_flame_how

Tags: navigation