Octopress 搭建静态博客站点 --- 为站点侧边栏添加标签云(Tag Cloud)
2016-10-12 03:18
701 查看
下载
首先到 https://github.com/robbyedwards/octopress-tag-pages 和 https://github.com/robbyedwards/octopress-tag-cloud clone这两个项目的代码。``` $ git clone https://github.com/robbyedwards/octopress-tag-cloud.git $ git clone https://github.com/robbyedwards/octopress-tag-cloud.git ```
octopress-tag-pages
Step 1 . 将octopress-tag-pages\plugins路径里面的
tag_generator.rb文件复制到
octopress\plugins\文件夹里面。
Step 2 . 将
octopress-tag-pages\source\_includes\custom路径里面的
tag_feed.xml文件复制到
octopress\source\_includes\custom\文件夹。
Step 3 . 将
octopress-tag-pages\source\_layouts路径里面的
tag_index.html文件复制到
octopress\source\_layouts\文件夹里。
octopress-tag-cloud
Step 1 . 将octopress-tag-cloud\plugins路径里面的
tag_cloud.rb文件复制到
octopress\plugins\文件夹里面。
Step 2 . 将下面的代码复制到
octopress\source\_includes\custom\asides\tags.html。(这个文件需要你自己新建。)
注意: 先去掉
%前面的反斜杠。
<section> <h1>Tags</h1> <ul class="tag-cloud"> {\% tag_cloud font-size: 90-210%, limit: 15, style: para \%} </ul> </section>
解释上面这段代码:
tag_cloud的参数中。
font-size指定
tag的大小范围;
limit限定
15个
tag;
style :para指定不使用
li来分割。
Step 3 .
在
octopress\_config.yml中的
default_asides中添加
custom/asides/tags.html。
default_asides: [custom/asides/tags.html, .....]
现在执行
rake generate生成博客。在使用
rake preview在本地预览博客。
你会发现,在导航栏里面出现了 Tags 字段,但是里面没有标签。(不用担心,你已经成功添加了标签云。只不过你的博文里面没有标签,所以在标签云里面就没有标签。)
我们写一个带标签的博文。怎么写一个带标签的博文:
tags: [tag1, tag2, tag3]
执行
rake generate命令时出现了问题:
解决:comparison of Array with Array failed in _layouts/page.html
错误
Liquid Exception: comparison of Array with Array failed in _layouts/page.html
在
octopress\plugins\tag_cloud.rb中第74行是这么写的:
if @limit > 0 and @sort != 'rand' # sort the tag pairs by frequency in descending order weighted.sort! { |a,b| b[1] <=> a[1] } # then slice off the top @limit tag pairs weighted = weighted[0,@limit] end
weighted = weighted[0,@limit]应该就是取指定数目的标签。如果你的标签数量少于
@limit,那么就会报错。
所以我们修改第74行为:
if @limit > 0 and @sort != 'rand' and @limit < weighted.length
同样的,将第95行修改为:
if @limit > 0 and @limit < weighted.length
现在所有的修改都完成了,执行
rake generate命令时,就不会再出现上面的错误了,但是现在却出现了下面的警告:
我们现在执行
rake preview命令来预览看看。标签云是成功添加上去了:
解决 Build Warning: Layout 'nil' requested in tags/标签名/atom.xml does not exist.
警告问题
将 octopress\source\_includes\custom\tag_feed.xml文件里面
nil改为
null:
--- layout: null ---
搞定,现在再执行
rake generate命令就不会出现这个警告了。不会出现任何问题。
搞定
参考网站:(扩充)为 octopress 添加标签云:
http://yang3wei.github.io/blog/2013/01/30/zhuan-zai-wei-octopress-tian-jia-biao-qian-yun/
分类标签:
http://wiki.jikexueyuan.com/project/github-page/classification.html
在Octopress中添加标签:
http://devma.cn/blog/2016/04/02/zai-octopresszhong-tian-jia-biao-qian/
请访问:http://www.aobosir.com/
相关文章推荐
- Octopress 搭建静态博客站点 --- 为站点侧边栏添加分类列表(Categories)
- Octopress 搭建静态博客站点 --- 添加访客统计
- Octopress 搭建静态博客站点 — 让中文的分类列表(Categories)的超链接正常使用
- Octopress 搭建静态博客网站
- 使用Octopress搭建静态博客网站
- 利用Octopress在Github上搭建博客及后续问题总汇
- 为octopress添加tag Cloud
- 在github上用octopress搭建博客过程纪要
- 在github上用octopress搭建博客过程纪要
- 在Mac上从零开始搭建基于Github的Octopress博客
- 一款Octopress插件用于同步博客到其他站点
- 在github上搭建octopress博客 Mac
- 在github Pages上部署octopress搭建个人博客系统
- 在github Pages上部署octopress搭建个人博客系统
- Octopress博客搭建
- 使用Octopress和Github Pages搭建博客的高级技巧
- Windows下搭建Octopress博客
- octopress博客搭建和个性化配置
- 用Github和Octopress搭建博客
- Octopress博客搭建及目录结构