Merge branch 'meta_feature'

This commit is contained in:
yafeilee 2014-04-02 15:06:52 +08:00
commit a6d18cb05f
4 changed files with 19 additions and 1 deletions

View File

@ -44,8 +44,17 @@ class Post
self.visited_count
end
# 显示给首页截断数据
def sub_content
HTML_Truncator.truncate(content_html,30)
HTML_Truncator.truncate(content_html, 300, length_in_chars: true)
end
# 显示给 meta description
def meta_content
html = HTML_Truncator.truncate(content_html, 100, :length_in_chars => true, ellipsis: '')
# 加上 div 以方便 Nokogiri 获取 text()
html = '<div>' + html + '</div>'
Nokogiri.parse(html).text()
end
def labels_content( need_blank=false )

View File

@ -1,3 +1,6 @@
- if ENV['INTRODUCE'].present?
- content_for(:meta) do
meta name="description" content="#{ENV['INTRODUCE'].dup.force_encoding('UTF-8')}"
- content_for(:title) do
| 首页
.row

View File

@ -1,3 +1,7 @@
- content_for(:meta) do
meta name="description" content="#{@post.meta_content}"
meta name="keywords" content=@post.labels_content
- content_for(:title) do
| #{@post.title}
.row

View File

@ -2,6 +2,8 @@ html
head
meta charset="utf-8"
meta name="viewport" content="width=device-width, initial-scale=1.0"
- if content_for?(:meta)
= yield(:meta)
title
= content_for?(:title) ? yield(:title) + " | #{ENV['SITE_NAME']}" : ENV['SITE_NAME']
= stylesheet_link_tag "application"