分享

octopress的个性化配置

 思考的轨迹 2012-02-16

octopress的个性化配置

| Comments

octopress作为一个blog框架,提供了不少的个性化东东,方便大家根据自己的需求对blog做个性化,大部分都可以通过修改根目录下的 _config.yml搞定。这个配置文件本身的语法是YAML,关于YAML语言本身,有兴趣的可以看看这篇介绍文章

回到_config.yml本身,打开后发现内容就是key: value形式。这儿修改时,需要注意冒号和value之前必须有空格,否则在rake generate时,会报下面的解析错误:

1
2
3
4
5
6
7
8
9
10
11
## Generating Site with Jekyll
unchanged sass/screen.scss
/usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych.rb:148:in `parse': couldn't parse YAML at line 7 column 0 (Psych::SyntaxError)
   from /usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych.rb:148:in `parse_stream'
   from /usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych.rb:119:in `parse'
   from /usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych.rb:106:in `load'
   from /usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych.rb:205:in `load_file'
   from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/jekyll-0.11.0/lib/jekyll.rb:119:in `configuration'
   from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/jekyll-0.11.0/bin/jekyll:207:in `<top (required)>'
   from /usr/local/rvm/gems/ruby-1.9.2-p290/bin/jekyll:19:in `load'
   from /usr/local/rvm/gems/ruby-1.9.2-p290/bin/jekyll:19:in `<main>'

大部分配置项都可以从字面上看出什么意思,有些也有注释,这儿挑些说下。配置文件分为三个部分:

Main Configs

1
2
3
4
5
6
url: http://yoursite.com  # blog地址
title: My Octopress Blog  # blog名称,会出现在左上角
subtitle: A blogging framework # title下面的副标题,可以用来放你的喜欢的名人名言,或者简单介绍下自己
author: Your Name # 会出现在每篇文章下面的Posted by 
simple_search: http://google.com/search # 右边搜索框使用的搜索引擎
description: # head.html中meta name="description"的默认content,但一般都被会截断的文章内容替换掉

Jekyll & Plugins

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
root: / # 网站的根目录,如果你网站是http:///project这样的形式,就要写成 root: /project
# 生成文章的url形式,比如不喜欢url中带时间,习惯后缀加html,可以写成 /blog/:title.html
permalink: /blog/:year/:month/:day/:title/
paginate: 10          # 每页展现blog的数量,如果blog数量大于这个,会产生翻页
recent_posts: 5       # 右侧最近发表模块里blog的数量
# 在某篇blog中使用<!-- more -->,列表页就不会展现该blog全文,就会显示这个read on链接,指向blog全文
excerpt_link: "Read on &rarr;"
# 右侧边栏的展现,有些要下面的设置配合,比如你没有配置github_user,则这儿也不会展现github.html
# 也可以增加一些自己的页面,比如在/source/_includes/custom/asides/下增加about.html
# 然后在列表中增加custom/asides/about.html即可,这儿前后的顺序,就代表了页面上下的次序 
default_asides: [asides/recent_posts.html, asides/github.html, asides/twitter.html]
# 可以给不同的页面配置不同的侧边栏  
blog_index_asides:
post_asides:
page_asides:

3rd Party Settings

第三方的设置,在这不一一说了,一般都是填对应的用户名即可。支持的有:github、twitter、google +1、pinbord、disqus、Google Analytics等。disqus作为评论插件,google analytics作为网站分析工具,强烈建议填上。没有账号的可以点击链接去申请。至于sina微博,直接在页面嵌入他家的iframe就行了,效果如右侧所示

其他配置

  • 通过修改octopress/sass/custom/_layout.scss中$indented-lists: true可以让文章中列表和每行对齐,展现效果就如本文中列表
  • 在source目录下增加robots.txt,允许或者禁止搜索引擎抓取
  • 在source增加404.html,给出更友好的出错提示,一个简单的获取所有文章的404页面代码如下:
(404.html) download
1
2
3
4
5
6
7
8
9
10
11
12
13
---
layout: page
title: 抱歉,你要访问的网页不存在
footer: false
---
<h3> 看看下面有木有你要找的东东?</h3>
<div id="blog-archives">
{% for post in site.posts limit: 10 %}
<article>
  {% include archive_post.html %}
</article>
{% endfor %}
</div>

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多