讓octopress支持標籤(tag)

安裝插件

目前有多個插件實現標籤功能。其中一個是octopress官方推薦版本,聽說不支持多標籤。還有些人用的是「3D」標籤雲,風格上我不是太喜歡。最終選用的是robbyedwards的一組插件。這組插件有兩個,一個是octopress-tag-pages,用於生成標籤頁面,另外一個是octopress-tag-cloud,用於顯示實現標籤雲功能。css

### octopress-tag-pageshtml

首先安裝octopress-tag-page。從上面連接處獲得插件,複製這些文件到octopress的相同路徑:git

plugins/tag_generator.rbgithub

source/_includes/custom/tag_feed.xmlmarkdown

source/_includes/post/tags.htmlapp

source/_layouts/tag_index.htmlide

其中tag_generator.rb和tag_feed.xml是必須的,其它據網上的一些人說是可選的。post

另一些文件是同名文件,若是複製過來一方面會影響已經配置的功能,另外可能致使發生一些問題(多是版本兼容的問題形成的)。測試

這個插件不須要作配置。ui

octopress-tag-cloud

而後安裝octopress-tag-cloud。在上面連接處獲得插件,一樣複製一些文件到octopress的相同路徑:

plugins/tag_cloud.rb

source/_includes/custom/asides/tags.html

tag_cloud.rb爲必須。tags.html爲在側邊欄顯示標籤的示例。能夠參照它進行配置。

在側邊欄顯示標籤雲

在_config.yml中的default_asides:中增長custom/asides/tags.html,用於在側邊欄顯示標籤雲。若是想漢化,則修改tags.html等文件便可。

使用

在新建的博客文件中加入一行「tags: 」,相似:

---
layout: post
title: "test tag"
published: true
date: 2014-10-28 00:42
comments: true
tags: [擴展, ttt]
categories: 
---

這樣會給這一博文增長兩個標籤,使標籤與分類對文章進行不一樣維度的分類。

當有文章有多個標籤時,在執行rake generate時會出現相似以下問題:

1
2
3
4
5
6
7
8
9
10
$ rake generate (in /ubdata/octopress) ## Generating Site with Jekyll identical source/stylesheets/screen.css Configuration file: /ubdata/octopress/_config.yml  Source: source  Destination: public  Generating...  Liquid Exception: comparison of Array with Array failed in _layouts/page.html jekyll 2.4.0 | Error: comparison of Array with Array failed 

經十幾天的反覆測試,發如今source/_includes/custom/asides/tags.html若是加了「limit」參數,就會出現問題。去掉就行了。

另外一個問題是2.0版本的ocroptrss調用的generate操做會執行plugings中的全部插件,因此會報一些錯,忽略便可。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ rake generate (in /ubdata/octopress) ## Generating Site with Jekyll identical source/stylesheets/screen.css Configuration file: /ubdata/octopress/_config.yml  Source: source  Destination: public  Generating...  Build Warning: Layout 'nil' requested in tags/kuo-zhan/atom.xml does not exist.  Build Warning: Layout 'nil' requested in tags/ttt/atom.xml does not exist.  Build Warning: Layout 'nil' requested in tags/kuo-zhan/atom.xml does not exist.  Build Warning: Layout 'nil' requested in tags/ttt/atom.xml does not exist.  done.  Auto-regeneration: disabled. Use --watch to enable.

參考

http://codemacro.com/2012/07/18/add-tag-to-octopress/

http://loudou.info/blog/2014/02/15/wei-octopress-tian-jia-tag-gong-neng/

相關文章
相關標籤/搜索