Permalink
Browse files

naive related posts implementation

  • Loading branch information...
mojombo committed Nov 3, 2008
1 parent b2d2d09 commit c98911f5c1bb5457622a1ce0297e2844e56ef329
Showing with 20 additions and 9 deletions.
  1. +10 −4 lib/autoblog/post.rb
  2. +10 −5 lib/autoblog/site.rb
View
@@ -63,14 +63,20 @@ def transform
self.content = RedCloth.new(self.content).to_html
end
def add_layout(layouts)
payload = {"page" => self.data}
self.content = Liquid::Template.parse(self.content).render(payload)
def related_posts(posts)
related = posts - [self]
end
def add_layout(layouts, site_payload)
related = related_posts(site_payload["site"]["posts"])
payload = {"page" => self.data, "related_posts" => related}.merge(site_payload)
self.content = Liquid::Template.parse(self.content).render(payload, [AutoBlog::Filters])
layout = layouts[self.data["layout"]] || self.content
payload = {"content" => self.content, "page" => self.data}
self.output = Liquid::Template.parse(layout).render(payload)
self.output = Liquid::Template.parse(layout).render(payload, [AutoBlog::Filters])
end
def write(dest)
View
@@ -47,24 +47,29 @@ def read_posts
def write_posts
self.posts.each do |post|
post.add_layout(self.layouts)
post.add_layout(self.layouts, site_payload)
post.write(self.dest)
end
end
def transform_pages(dir = '')
base = File.join(self.source, dir)
entries = Dir.entries(base)
entries = entries.reject { |e| %w{_layouts posts}.include?(e) }
entries = entries.reject { |e| %w{_layouts posts drafts}.include?(e) }
entries = entries.reject { |e| e[0..0] == '.' }
entries.each do |f|
if File.directory?(File.join(base, f))
transform_pages(File.join(dir, f))
else
page = Page.new(self.source, dir, f)
page.add_layout(self.layouts, site_payload)
page.write(self.dest)
if %w{.png .jpg .gif}.include?(File.extname(f))
FileUtils.mkdir_p(File.join(self.dest, dir))
FileUtils.cp(File.join(self.source, dir, f), File.join(self.dest, dir, f))
else
page = Page.new(self.source, dir, f)
page.add_layout(self.layouts, site_payload)
page.write(self.dest)
end
end
end
end

0 comments on commit c98911f

Please sign in to comment.