同添加category list一樣,網絡上有很多方法,這裏列舉一種。首先到https://github.com/robbyedwards/octopress-tag-pages和https://github.com/robbyedwards/octopress-tag-cloudclone這兩個項目的代碼。這兩個項目分別用於產生tag page和tag cloud。 針對這兩個插件,需要手工複製一些文件到你的octopress目錄。
octopress-tag-pages
複製tag_generator.rb到/plugins目錄;複製tag_index.html到/source/_layouts目錄。需要注意的是,還需要複製tag_feed.xml到/source/_includes/custom/目錄。這個官方文檔裏沒提到,在我機器上rake generate時報錯。其他文件就不需要複製了,都是些例子。
octopress-tag-cloud
僅複製tag_cloud.rb到/plugins目錄即可。但這僅僅只是爲liquid添加了一個tag(非本文所提tag)。如果要在側邊導航裏添加一個tag cloud,我們還需要手動添加aside。
複製以下代碼到/source/_includes/custom/asides/tags.html。
<section>
<h1>Tags</h1>
<ul class="tag-cloud">
{% tag_cloud font-size: 90-210%, limit: 10, style: para %}
</ul>
</section>
tag_cloud的參數中,style :para指定不使用li來分割,limit限定10個tag,font-size指定tag的大小範圍,具體參數參看官方文檔。
最後,當然是在_config.xml的default_asides 中添加這個tag cloud到導航欄,例如:
default_asides: [asides/category_list.html, asides/recent_posts.html, custom/asides/tags.html]