Octopress 搭建静态博客站点 — 让中文的分类列表(Categories)的超链接正常使用
2016-11-29 18:44
423 查看
前言
之前,我是按照我写的这篇博客为Octopress站点侧边栏添加分类列表(Categories)。出现的问题
基于Octopress的博客系统自带了一个很好用分类目录插件。但遗憾的是它不支持中文链接URL,所以导致了:如果你分类列表有中文,那么点击的时候会链接到404页面。解决思路
中文取拼音。解决方法
参考网站:解决Octopress分类目录支持中文的问题/plugins/category_sidebar.rb(若没有,自行创建)
require 'stringex' 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 html << "<li class='category'><a href='/blog/categories/#{category.to_url.downcase}/'>#{category} (#{posts_in_category})</a></li>\n" end html end end end Liquid::Template.register_tag('category_sidebar', Jekyll::CategoryListTag)
搞定
现在你可以重新执行rake generate和
rake preview、
rake deploy,分类列表中有中文字符的分类,就可以正常打开了,而实际的链接就是对应的拼音。
请访问:http://www.aobosir.com/
相关文章推荐
- Octopress 搭建静态博客站点 --- 为站点侧边栏添加分类列表(Categories)
- Octopress 搭建静态博客站点 --- 添加访客统计
- 使用Octopress搭建静态博客网站
- Octopress 搭建静态博客站点 --- 为站点侧边栏添加标签云(Tag Cloud)
- 使用github+octopress搭建个人技术博客
- 使用Octopress博客 搭建博客
- Octopress 搭建静态博客网站
- 使用github + Octopress 搭建免费博客 + 碰到问题的解决方法
- Mac下使用Octopress搭建博客详细教程-芒果iOS
- 使用github与Octopress 搭建GitHub Pages博客
- 使用Octopress和Github Pages搭建博客的高级技巧
- 使用Octopress在Github上搭建博客系统
- Windows下搭建Octopress博客
- Octopress博客搭建及目录结构
- 在github上搭建octopress博客 Mac
- 用Github和Octopress搭建博客
- Octopress博客搭建
- octopress博客搭建和个性化配置
- 利用Octopress在github pages上搭建个人博客
- [Pelican] 使用Pelican搭建静态博客