handle atom feed generation
This commit is contained in:
parent
07fe6cd128
commit
4ef3aedb6a
|
@ -4,6 +4,14 @@ module AutoBlog
|
||||||
def date_to_string(date)
|
def date_to_string(date)
|
||||||
date.strftime("%d %b %Y")
|
date.strftime("%d %b %Y")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def date_to_xmlschema(date)
|
||||||
|
date.xmlschema
|
||||||
|
end
|
||||||
|
|
||||||
|
def xml_escape(input)
|
||||||
|
input.gsub("<", "<").gsub(">", ">")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
|
@ -9,6 +9,8 @@ module AutoBlog
|
||||||
@dir = dir
|
@dir = dir
|
||||||
@name = name
|
@name = name
|
||||||
|
|
||||||
|
self.data = {}
|
||||||
|
|
||||||
self.process(name)
|
self.process(name)
|
||||||
self.read_yaml(base, dir, name)
|
self.read_yaml(base, dir, name)
|
||||||
self.set_defaults
|
self.set_defaults
|
||||||
|
@ -40,8 +42,8 @@ module AutoBlog
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_layout(layouts, posts)
|
def add_layout(layouts, site_payload)
|
||||||
payload = {"page" => self.data, "site" => {"posts" => posts}}
|
payload = {"page" => self.data}.merge(site_payload)
|
||||||
self.content = Liquid::Template.parse(self.content).render(payload, [AutoBlog::Filters])
|
self.content = Liquid::Template.parse(self.content).render(payload, [AutoBlog::Filters])
|
||||||
|
|
||||||
layout = layouts[self.data["layout"]] || self.content
|
layout = layouts[self.data["layout"]] || self.content
|
||||||
|
|
|
@ -8,7 +8,7 @@ module AutoBlog
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_accessor :date, :slug, :ext
|
attr_accessor :date, :slug, :ext
|
||||||
attr_accessor :data, :content
|
attr_accessor :data, :content, :output
|
||||||
|
|
||||||
def initialize(base, name)
|
def initialize(base, name)
|
||||||
@base = base
|
@base = base
|
||||||
|
@ -60,7 +60,7 @@ module AutoBlog
|
||||||
layout = layouts[self.data["layout"]] || self.content
|
layout = layouts[self.data["layout"]] || self.content
|
||||||
payload = {"content" => self.content, "page" => self.data}
|
payload = {"content" => self.content, "page" => self.data}
|
||||||
|
|
||||||
self.content = Liquid::Template.parse(layout).render(payload)
|
self.output = Liquid::Template.parse(layout).render(payload)
|
||||||
end
|
end
|
||||||
|
|
||||||
def write(dest)
|
def write(dest)
|
||||||
|
@ -68,14 +68,15 @@ module AutoBlog
|
||||||
|
|
||||||
path = File.join(dest, self.url)
|
path = File.join(dest, self.url)
|
||||||
File.open(path, 'w') do |f|
|
File.open(path, 'w') do |f|
|
||||||
f.write(self.content)
|
f.write(self.output)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_liquid
|
def to_liquid
|
||||||
{ "title" => self.data["title"] || "",
|
{ "title" => self.data["title"] || "",
|
||||||
"url" => self.url,
|
"url" => self.url,
|
||||||
"date" => self.date }
|
"date" => self.date,
|
||||||
|
"content" => self.content }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -63,11 +63,15 @@ module AutoBlog
|
||||||
transform_pages(File.join(dir, f))
|
transform_pages(File.join(dir, f))
|
||||||
else
|
else
|
||||||
page = Page.new(self.source, dir, f)
|
page = Page.new(self.source, dir, f)
|
||||||
page.add_layout(self.layouts, self.posts)
|
page.add_layout(self.layouts, site_payload)
|
||||||
page.write(self.dest)
|
page.write(self.dest)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def site_payload
|
||||||
|
{"site" => {"time" => Time.now, "posts" => self.posts}}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
Loading…
Reference in New Issue