def self.process(options)
source = options.fetch("source")
layout = options.fetch("layout")
avoid_liquid = options.fetch("avoid_liquid")
FileUtils.mkdir_p("_posts")
FileUtils.mkdir_p("_drafts")
Dir.glob("*.xml", :base => source).each do |df|
df = File.join(source, df)
filename = File.basename(df, ".*")
a_filename = filename.split(".")
post_name = a_filename.pop
file_date = a_filename.pop
post_date = file_date[0..3] + "-" + file_date[4..5] + "-" + file_date[6..7]
if filename.split(".")[1].split(",")[0] == "draft"
directory = "_drafts"
name = post_name.to_s
else
directory = "_posts"
name = "#{post_date}-#{post_name}"
end
xml = File.open(df) { |f| Nokogiri::XML(f) }
raise "There doesn't appear to be any XML items at the source (#{df}) provided." unless xml
doc = xml.xpath("document")
header = {
"layout" => layout,
"title" => doc.xpath("title").text,
"tags" => doc.xpath("tags").text.split(", "),
}
header["render_with_liquid"] = false if avoid_liquid
path = File.join(directory, "#{name}.html")
File.open(path, "w") do |f|
f.puts header.to_yaml
f.puts "---\n\n"
f.puts doc.xpath("chapo").text
f.puts doc.xpath("content").text
end
Jekyll.logger.info "Wrote file #{path} successfully!"
end
nil
end