Added meta tag import goodness. This for instance allows you to preserve all your hard-worked on WP SEO keywords, images, alternative images and other yummy-ness.
Replaced PubDate with wp:post_date, this is better than PubDate since some of the posts you import could be a draft (in this case the pubDate is invalid and contains a non-sensical value). Added wp:status so we now know whether the post is published, draft or in the trash. Added wp:post_type so we differentiate between posts and image or other post types
This commit is contained in:
parent
e679729ac7
commit
365f57e8b3
|
@ -4,6 +4,7 @@ require 'rubygems'
|
|||
require 'hpricot'
|
||||
require 'fileutils'
|
||||
require 'yaml'
|
||||
require 'time'
|
||||
|
||||
module Jekyll
|
||||
# This importer takes a wordpress.xml file, which can be exported from your
|
||||
|
@ -18,13 +19,26 @@ module Jekyll
|
|||
(doc/:channel/:item).each do |item|
|
||||
title = item.at(:title).inner_text.strip
|
||||
permalink_title = item.at('wp:post_name').inner_text
|
||||
date = Time.parse(item.at(:pubDate).inner_text)
|
||||
date = Time.parse(item.at('wp:post_date').inner_text)
|
||||
status = item.at('wp:status').inner_text
|
||||
type = item.at('wp:post_type').inner_text
|
||||
tags = (item/:category).map{|c| c.inner_text}.reject{|c| c == 'Uncategorized'}.uniq
|
||||
|
||||
metas = Hash.new
|
||||
item.search("wp:postmeta").each do |meta|
|
||||
key = meta.at('wp:meta_key').inner_text
|
||||
value = meta.at('wp:meta_value').inner_text
|
||||
metas[key] = value;
|
||||
end
|
||||
|
||||
name = "#{date.strftime('%Y-%m-%d')}-#{permalink_title}.html"
|
||||
header = {
|
||||
'layout' => 'post',
|
||||
'title' => title,
|
||||
'tags' => tags
|
||||
'tags' => tags,
|
||||
'status' => status,
|
||||
'type' => type,
|
||||
'meta' => metas
|
||||
}
|
||||
|
||||
File.open("_posts/#{name}", "w") do |f|
|
||||
|
|
Loading…
Reference in New Issue