mirror of
https://github.com/samsonjs/samhuri.net.git
synced 2026-04-27 14:57:40 +00:00
fix missing content in rss feed
This commit is contained in:
parent
7ea8f50270
commit
52413d33a6
4 changed files with 27 additions and 31 deletions
34
blog.rb
34
blog.rb
|
|
@ -51,9 +51,8 @@ class Blag
|
||||||
# generate landing page
|
# generate landing page
|
||||||
index_template = File.read(File.join('templates', 'blog', 'index.html'))
|
index_template = File.read(File.join('templates', 'blog', 'index.html'))
|
||||||
post = posts.first
|
post = posts.first
|
||||||
template = post[:link] ? link_template : post_template
|
|
||||||
values = { :post => post,
|
values = { :post => post,
|
||||||
:article => Mustache.render(template, post),
|
:article => Mustache.render(template(post[:type]), post),
|
||||||
:previous => posts[1],
|
:previous => posts[1],
|
||||||
:filename => post[:filename],
|
:filename => post[:filename],
|
||||||
:comments => post[:comments]
|
:comments => post[:comments]
|
||||||
|
|
@ -65,10 +64,9 @@ class Blag
|
||||||
def generate_posts
|
def generate_posts
|
||||||
page_template = File.read(File.join('templates', 'blog', 'post.html'))
|
page_template = File.read(File.join('templates', 'blog', 'post.html'))
|
||||||
posts.each_with_index do |post, i|
|
posts.each_with_index do |post, i|
|
||||||
template = post[:link] ? link_template : post_template
|
|
||||||
values = { :title => post[:title],
|
values = { :title => post[:title],
|
||||||
:link => post[:link],
|
:link => post[:link],
|
||||||
:article => Mustache.render(template, post),
|
:article => Mustache.render(template(post[:type]), post),
|
||||||
:previous => i < posts.length - 1 && posts[i + 1],
|
:previous => i < posts.length - 1 && posts[i + 1],
|
||||||
:next => i > 0 && posts[i - 1],
|
:next => i > 0 && posts[i - 1],
|
||||||
:filename => post[:filename],
|
:filename => post[:filename],
|
||||||
|
|
@ -116,9 +114,9 @@ class Blag
|
||||||
post[:url] = @url + '/' + post[:filename]
|
post[:url] = @url + '/' + post[:filename]
|
||||||
post[:timestamp] = post[:timestamp].to_i
|
post[:timestamp] = post[:timestamp].to_i
|
||||||
post[:content] = lines.join
|
post[:content] = lines.join
|
||||||
template = post[:link] ? link_rss_template : post_rss_template
|
|
||||||
post[:rss_html] = Mustache.render(template, {:post => post})
|
|
||||||
post[:body] = RDiscount.new(post[:content]).to_html
|
post[:body] = RDiscount.new(post[:content]).to_html
|
||||||
|
post[:type] = post[:link] ? :link : :post
|
||||||
|
post[:rss_html] = Mustache.render(rss_template(post[:type]), {:post => post})
|
||||||
post[:rfc822] = Time.at(post[:timestamp]).rfc822
|
post[:rfc822] = Time.at(post[:timestamp]).rfc822
|
||||||
post[:tags] = (post[:tags] || '').split(/\s*,\s*/).map(&:strip)
|
post[:tags] = (post[:tags] || '').split(/\s*,\s*/).map(&:strip)
|
||||||
# comments on by default
|
# comments on by default
|
||||||
|
|
@ -133,24 +131,28 @@ class Blag
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def post_template
|
def template(type)
|
||||||
|
if type == :post
|
||||||
@post_template ||= File.read(File.join('templates', 'blog', 'post.mustache'))
|
@post_template ||= File.read(File.join('templates', 'blog', 'post.mustache'))
|
||||||
end
|
elsif type == :link
|
||||||
|
|
||||||
def link_template
|
|
||||||
@link_template ||= File.read(File.join('templates', 'blog', 'link.mustache'))
|
@link_template ||= File.read(File.join('templates', 'blog', 'link.mustache'))
|
||||||
|
else
|
||||||
|
raise 'unknown post type: ' + type
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def blog_file
|
def blog_file
|
||||||
File.join(@src, 'blog.json')
|
File.join(@src, 'blog.json')
|
||||||
end
|
end
|
||||||
|
|
||||||
def post_rss_template
|
def rss_template(type)
|
||||||
|
if type == :post
|
||||||
@post_rss_template ||= File.read(File.join('templates', 'blog', 'post.rss.html'))
|
@post_rss_template ||= File.read(File.join('templates', 'blog', 'post.rss.html'))
|
||||||
end
|
elsif type == :link
|
||||||
|
|
||||||
def link_rss_template
|
|
||||||
@link_rss_template ||= File.read(File.join('templates', 'blog', 'link.rss.html'))
|
@link_rss_template ||= File.read(File.join('templates', 'blog', 'link.rss.html'))
|
||||||
|
else
|
||||||
|
raise 'unknown post type: ' + type
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_blog
|
def read_blog
|
||||||
|
|
@ -168,7 +170,7 @@ class Blag
|
||||||
title = options[:title] || @title
|
title = options[:title] || @title
|
||||||
subtitle = options[:subtitle] || @subtitle
|
subtitle = options[:subtitle] || @subtitle
|
||||||
url = options[:url] || @url
|
url = options[:url] || @url
|
||||||
posts ||= options[:posts] || method(:posts).call
|
posts ||= options[:posts] || self.posts[0, 10]
|
||||||
|
|
||||||
xml = Builder::XmlMarkup.new
|
xml = Builder::XmlMarkup.new
|
||||||
xml.instruct! :xml, :version => '1.0'
|
xml.instruct! :xml, :version => '1.0'
|
||||||
|
|
@ -182,7 +184,7 @@ class Blag
|
||||||
|
|
||||||
posts.each do |post|
|
posts.each do |post|
|
||||||
xml.item do
|
xml.item do
|
||||||
xml.title post[:link] ? "→ #{post[:title]}" : post[:title]
|
xml.title post[:link] ? "#{post[:title]} →" : post[:title]
|
||||||
xml.description post[:rss_html]
|
xml.description post[:rss_html]
|
||||||
xml.pubDate post[:rfc822]
|
xml.pubDate post[:rfc822]
|
||||||
xml.author post[:author]
|
xml.author post[:author]
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<article>
|
<article>
|
||||||
<header>
|
<header>
|
||||||
<h2><a href="{{link}}">→ {{title}}</a></h2>
|
<h2><a href="{{link}}">{{title}} →</a></h2>
|
||||||
<time>{{date}}</time>
|
<time>{{date}}</time>
|
||||||
</header>
|
</header>
|
||||||
{{{body}}}
|
{{{body}}}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,7 @@
|
||||||
<div id="article">
|
<div id="article">
|
||||||
{{#post}}
|
{{#post}}
|
||||||
<header>
|
|
||||||
<h1><a href="{{link}}">→ {{title}}</a></h1>
|
|
||||||
<p class="time">{{date}}</p>
|
<p class="time">{{date}}</p>
|
||||||
</header>
|
{{{body}}}
|
||||||
{{{html}}}
|
|
||||||
<p><a class="permalink" href="{{url}}">∞</a></p>
|
<p><a class="permalink" href="{{url}}">∞</a></p>
|
||||||
{{/post}}
|
{{/post}}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,6 @@
|
||||||
<div id="article">
|
<div id="article">
|
||||||
{{#post}}
|
{{#post}}
|
||||||
<header>
|
|
||||||
<h1><a href="{{url}}">{{title}}</a></h1>
|
|
||||||
<p class="time">{{date}}</p>
|
<p class="time">{{date}}</p>
|
||||||
</header>
|
{{{body}}}
|
||||||
{{{html}}}
|
|
||||||
{{/post}}
|
{{/post}}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue