Baham's Blog

Above all else, guard your heart.

Some Octopress Tools: SEO, Add the Original Link

Octopress is a very cool blog system, you can generae posts by jeklly.

And push your site to github.

Since I found my blog get a pr 2, I always think how to SEO my blog. And thkans to Google, I found some tools.

Add Original Link after the Post

Mr Sunshine write an article about how to add space between Chinese Word and English Word. Inspired by this, Kevin write a ruby plugin to add the original link after the octopress post. It is awesome.

And Tiny change the plugin to add the keyword after the octopress post also. So I just read the source code and add edit it for myself.

These are the source code for octopress-add-original-link.rb

octopress-add-original-linklink
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# To change this license header, choose License Headers in Project Properties.
# To change this template file, choose Tools | Templates
# and open the template in the editor.

require './plugins/post_filters'

module AppendFooterFilter
  def append(post)
     author = post.site.config['author']
     url = post.site.config['url']
     pre = post.site.config['original_url_pre']
     license = post.site.config['license_url']
     lic_name = post.site.config['license_name']
     post.content +  " "+ <<_here2start
<p class='post-footer' style="font-size:70%;" >
<br/>
<br/>
<br/>
#{pre or "The Original Link:"}
<a href='#{post.full_url}' rel="bookmark">#{post.full_url}</a><br/>
If you want to reprint it, please do under the  <a href=#{license} >#{lic_name}</a>. 
</p>
_here2start

            #&nbsp;Posted at <a href='#{url}'>#{url}</a><br/>
            #&nbsp;Written by <a href='#{url}'>#{author}</a>
            #&nbsp;Keywords : SEO, Original Link
  end
end

module Jekyll
  class AppendFooter < PostFilter
    include AppendFooterFilter
    def pre_render(post)
      post.content = append(post) if post.is_post?
    end
  end
end

Liquid::Template.register_filter AppendFooterFilter

The file is here—octopress-add-original-link.rb please use the below link to download the newer one

And the newer version that fix a bug is in add-original-link version2

And after I modified, It is only can show the post’s original link.

Before you use it, you need to edit your _config.yml, and add these.

original_url_pre: "The Original Link: "
license_url: /license
license_name: "CC BY-NC-SA 4.0"

The contents after : , you need edit them by yourself for your site.

Add Keywords and Description for the Post and the Page

It will look like this:

keyword

And what you need to do is just add post.puts "keywords: " post.puts "description: " in your Rakefile

Like this


  puts "Creating new post: #{filename}"
  open(filename, 'w') do |post|
    post.puts "---"
    post.puts "layout: post"
    post.puts "title: \"#{title.gsub(/&/,'&')}\""
    post.puts "date: #{Time.now.strftime('%Y-%m-%d %H:%M')}"
    post.puts "comments: true"
    post.puts "categories: "
    post.puts "keywords: "
    post.puts "description: "
    post.puts "---"

Maybe you will need CTRL+Fto find the post.puts

And it is the same as adding the keywords and description to the page in octopress.

Add the Keywords And Description to The Whole Octopress Site

It is more easy, just add

description: "Description for the website"
keywords: "keywords, for, the, website"

in your octopress’s _config.yml file, and modify the source/_includes/head.html after the author meta like this:

(add_keywords_and_description.rb) download
1
2
3
4
   {% 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 }}" />
 {% capture keywords %}{% if page.keywords %}{{ page.keywords }}{% elsif site.keywords %}{{ site.keywords }}{% endif %}{% endcapture %}
 <meta name="keywords" content="{{ keywords | strip_html | condense_spaces }}" />

After the modifying, when you check the keywords and Description, they will show what you add in _config.yml

The above code was optimizated by myself, this is the new version with optimization about site’s description and keywords .

Add description and keywords version3

I think you will like it, my octopressers.

Reference Articles:

Kevin Lynx’s Blog

Tiny

Irshad Pananilath




The Original Link: http://baham.github.io/04_29_octopress-seo.html
If you want to reprint it, please do under the CC BY-NC-SA 4.0

Comments