mirror of
https://github.com/wezm/wezm.net.git
synced 2024-12-18 18:29:54 +00:00
Generate a rewrite map from old to new content
This commit is contained in:
parent
c93cb90268
commit
c634c6c752
2 changed files with 22 additions and 5 deletions
|
@ -2,11 +2,11 @@ require 'rubygems'
|
|||
|
||||
require 'wordpress'
|
||||
|
||||
if ARGV.size < 2
|
||||
puts "Usage importer.rb worpress-export.xml /path/to/nanoc/site"
|
||||
if ARGV.size < 3
|
||||
puts "Usage importer.rb worpress-export.xml /path/to/nanoc/site /path/to/rewrite_map"
|
||||
exit 3
|
||||
end
|
||||
|
||||
i = Importer::Wordpress.new(ARGV[0], ARGV[1])
|
||||
i = Importer::Wordpress.new(ARGV[0], ARGV[1], ARGV[2])
|
||||
|
||||
i.run
|
||||
|
|
|
@ -1,14 +1,17 @@
|
|||
require 'nokogiri'
|
||||
require 'nanoc3'
|
||||
require 'uri'
|
||||
|
||||
module Importer
|
||||
|
||||
class Wordpress
|
||||
|
||||
def initialize(wordpress_export_path, nanoc_site_path)
|
||||
def initialize(wordpress_export_path, nanoc_site_path, rewrite_map_path)
|
||||
@export_file = File.open(wordpress_export_path)
|
||||
@export = Nokogiri::XML(@export_file)
|
||||
@site = Nanoc3::Site.new(nanoc_site_path)
|
||||
@rewrite_map = []
|
||||
@rewrite_map_path = rewrite_map_path
|
||||
|
||||
load_categories
|
||||
load_tags
|
||||
|
@ -61,6 +64,7 @@ module Importer
|
|||
puts "Unknown post type: #{item_type}"
|
||||
end
|
||||
end
|
||||
write_rewrite_map
|
||||
end
|
||||
|
||||
protected
|
||||
|
@ -118,7 +122,7 @@ module Importer
|
|||
# require 'pp'
|
||||
# pp attributes
|
||||
|
||||
# add_item(content, attributes, identifier)
|
||||
add_item(content, attributes, path)
|
||||
end
|
||||
|
||||
def process_page(page)
|
||||
|
@ -140,10 +144,23 @@ module Importer
|
|||
# :excerpt => row['post_excerpt']
|
||||
# }
|
||||
# identifier = '/posts/' + post_date.year.to_s + '/' + post_date.month.to_s + '/' + post_name + '/'
|
||||
if attributes[:status] == 'publish'
|
||||
@rewrite_map << [attributes[:permalink], identifier]
|
||||
end
|
||||
@site.data_sources.first.create_item(content, attributes, identifier)
|
||||
puts "Added item at #{identifier}"
|
||||
end
|
||||
|
||||
def write_rewrite_map
|
||||
File.open(@rewrite_map_path, 'w') do |f|
|
||||
@rewrite_map.each do |old_url, new_path|
|
||||
uri = URI.parse(old_url)
|
||||
f.puts uri.path + "\t" + new_path
|
||||
puts uri.path + " => " + new_path
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue