Created
August 16, 2010 07:26
-
-
Save maxim/526571 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'wpxml_parser' | |
require 'nanoc3' | |
require 'fileutils' | |
XML_PATH = 'data.xml' | |
NANOC_PATH = '.' | |
class WordpressNanocImporter | |
include WpxmlParser | |
def initialize(source_xml_path, target_path) | |
@target_path = target_path | |
@blog = Blog.new(source_xml_path) | |
end | |
def run | |
FileUtils.cd(@target_path) do | |
site = Nanoc3::Site.new('.') | |
@blog.posts.each do |post| | |
body = post.body | |
attributes = build_post_attributes(post) | |
identifier = build_post_identifier(post) | |
site.data_sources[0].create_item(body, attributes, identifier) | |
end | |
end | |
end | |
private | |
def build_post_attributes(post) | |
{ :title => post.title, | |
:created_at => post.date, | |
:kind => 'article', | |
:tags => post.categories } | |
end | |
def build_post_identifier(post) | |
"/#{post.slug}/" | |
end | |
end | |
importer = WordpressNanocImporter.new(XML_PATH, NANOC_PATH) | |
importer.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment