Octopress 搭建静态博客站点 --- 为站点侧边栏添加分类列表(Categories)
2016-10-12 16:31
477 查看
一共三步,很简单。跟着走就可以。
Step 1 . 增加
在
这个插件会向
Step 2 . 增加
在
注意: 去掉
Step 3 . 在
打开
参考网站:
为octopress添加分类(category)列表
http://codemacro.com/2012/07/18/add-category-list-to-octopress/
请访问:http://www.aobosir.com/
Step 1 . 增加
category_list插件
在
octopress\plugins\文件夹里面,新建一个文件,取名为:
category_list_tag.rb。并将下面的代码粘贴到里面。
module Jekyll class CategoryListTag < Liquid::Tag def render(context) html = "" categories = context.registers[:site].categories.keys categories.sort.each do |category| posts_in_category = context.registers[:site].categories[category].size category_dir = context.registers[:site].config['category_dir'] category_url = File.join(category_dir, category.gsub(/_|\P{Word}/, '-').gsub(/-{2,}/, '-').downcase) html << "<li class='category'><a href='/#{category_url}/'>#{category} (#{posts_in_category})</a></li>\n" end html end end end Liquid::Template.register_tag('category_list', Jekyll::CategoryListTag)
这个插件会向
liquid注册一个名为
category_list的
tag,该
tag就是以
li的形式将站点所有的
category组织起来。如果要将
category加入到侧边导航栏,需要增加一个
aside。
Step 2 . 增加
aside
在
octopress\source\_includes\asides\文件夹里面,新建一个文件,取名为:
category_list.html。并粘贴下面的代码:
注意: 去掉
%前面的
\。
<section> <h1>Categories</h1> <ul id="categories"> {\% category_list \%} </ul> </section>
Step 3 . 在
_config.yml文件里面 ,修改
default_asides项
打开
octopress\_config.yml文件,修改里面的
default_asides项,将
asides/category_list.html添加进去。
default_asides: [asides/category_list.html, ......]
搞定
现在,我们执行rake generate命令来生成最新的博客站点。然后执行
rake preview命令在本地预览博客站点。 看看修改后的效果。
参考网站:
为octopress添加分类(category)列表
http://codemacro.com/2012/07/18/add-category-list-to-octopress/
请访问:http://www.aobosir.com/
相关文章推荐
- Octopress 搭建静态博客站点 — 让中文的分类列表(Categories)的超链接正常使用
- Octopress 搭建静态博客站点 --- 为站点侧边栏添加标签云(Tag Cloud)
- Octopress 搭建静态博客站点 --- 添加访客统计
- Octopress 搭建静态博客网站
- 使用Octopress搭建静态博客网站
- 在Mac上从零开始搭建基于Github的Octopress博客
- 在github上搭建octopress博客 Mac
- 使用Octopress在Github上搭建博客系统
- 在 Github Pages 搭建的静态个人博客中添加 https 访问
- 在github上搭建octopress博客 Mac
- 一款Octopress插件用于同步博客到其他站点
- Mac下利用Octopress和Github搭建自己的技术博客
- Mac OS X搭建基于hexo的静态博客站点
- 用OCTOPRESS搭建博客系统
- 在github Pages上部署octopress搭建个人博客系统
- 使用github+octopress搭建个人技术博客
- 利用octopress在github搭建博客时遇到的若干问题
- Windows7下,用Octopress在Github上搭建博客
- 在github上用octopress搭建博客过程纪要
- Octopress博客搭建及目录结构