yang3wei的专栏

Enjoy my life!

Octopress 中的 SEO

| Comments

原文链接:
loop in codes – Kevin Lynx BLOG
Octopress 默认为每个页面添加 meta description,其内容为当前文章的前150个字符,
如果是首页就会是第一篇文章的前 150 个字符。这里主要通过增加 meta keywords 来提高 SEO。

为每篇文章增加 keywors 和 description

就像我的这篇博客,这下文章头得填很多数据了,有点麻烦:

code snippet 1
1
2
3
4
5
6
7
8
9
10
---
layout: post
title: "Octopress中的SEO"
date: 2012-09-06 19:02
comments: true
categories: tips
tags: [tips, octopress]
keywords: seo, octopress
description: Octopress默认为每个页面添加`meta description`,其内容为当前文章的前150个字符,如果是首页就会是第一篇文章的前150个字符。这里主要通过增加`meta keywords`来提高SEO。
---

这样,每篇文章页面头就会自动增加 meta keywords 项,description也会使用这里填的,
而不是自动为文章前若干个字符。这个功能的实现在 _includes/head.html 中。

code snippet 2
1
2
3
<meta name="author" content="Kevin Lynx">
<meta name="description" content="Octopress默认为每个页面添加`meta description`,其内容为当前文章的前150个字符,如果是首页就会是第一篇文章的前150个字符。这里主要通过增加`meta keywords`来提高SEO。 ">
<meta name="keywords" content="seo, octopress">

为页面 (Page) 增加 keywords

上面只是修正了每篇博客页面的 meta 信息,octopress 中还有几个页面需要修正,例如首页,
这个可以通过修改 _includes/head.html 来完成。替换相关内容为以下:

code snippet 3
1
2
3
4
<meta name="author" content="{{ site.author }}">
{% capture description %}{% if page.description %}{{ page.description }}{% elsif site.description %}{{ site.description }}{%else%}{{ content | raw_content }}{% endif %}{% endcapture %}
<meta name="description" content="{{ description | strip_html | condense_spaces | truncate:150 }}">
{% if page.keywords %}<meta name="keywords" content="{{ page.keywords }}">{%else%}<meta name="keywords" content="{{ site.keywords }}">{% endif %}

如果页面没有提供 keywords 或者 description 的话,
就使用 site 里的设置,也就需要修改 _config.yml

code snippet 4
1
2
description: loop in codes, Kevin Lynx blog
keywords: c/c++, mmo, game develop, lisp, ruby, lua, web development

Comments