1
0
Fork 0
forked from wezm/wezm.net

Merge branch 'master' of ssh://localhost:2222/~wmoore/Sites/wezm.net

This commit is contained in:
Wesley Moore 2009-11-19 19:28:45 +11:00
commit e83ae7064a

View file

@ -15,6 +15,7 @@ module Importer
end end
def load_categories def load_categories
puts "Loading categories"
@categories = {} @categories = {}
@export.xpath('//rss/channel/wp:category').each do |category| @export.xpath('//rss/channel/wp:category').each do |category|
name = get(category, 'wp:cat_name') name = get(category, 'wp:cat_name')
@ -29,7 +30,15 @@ module Importer
end end
def load_tags def load_tags
puts "Loading tags"
@tags = {} @tags = {}
@export.xpath('//rss/channel/wp:tag').each do |tag|
slug = get(tag, 'wp:tag_slug')
@tags[slug] = {
:slug => slug,
:name => get(tag, 'wp:tag_name'),
}
end
end end
def find_topmost_category(category) def find_topmost_category(category)
@ -57,7 +66,7 @@ module Importer
protected protected
def get(node, xpath) def get(node, xpath)
elem = node.xpath(xpath).first elem = node.at_xpath(xpath)
elem ? elem.content : nil elem ? elem.content : nil
end end
@ -80,6 +89,12 @@ module Importer
end end
categories.uniq! categories.uniq!
begin
post_date = Date.strptime(get(post, 'wp:post_date_gmt'), "%Y-%m-%d %H:%M:%S")
rescue ArgumentError
post_date = Date.today
end
attributes = { attributes = {
:tags => tags.uniq, :tags => tags.uniq,
:categories => categories, :categories => categories,
@ -88,27 +103,20 @@ module Importer
:slug => get(post, 'wp:post_name'), :slug => get(post, 'wp:post_name'),
:post_id => get(post, 'wp:post_id').to_i, :post_id => get(post, 'wp:post_id').to_i,
:post_date => get(post, 'wp:post_date_gmt'), :post_date => get(post, 'wp:post_date_gmt'),
:section => find_topmost_category(@categories[categories.first])[:slug],
:title => get(post, 'title'),
} }
if attributes[:slug].empty? if attributes[:slug].empty?
puts "WARNING: Error post #{attributes[:post_id]} has no slug" puts "WARNING: Error post #{attributes[:post_id]} has no slug, generating one"
#TODO prompt for slug or derive one from the title here attributes[:slug] = attributes[:title].downcase.gsub(/[^0-9a-zA-Z]/, '-').gsub(/-{2,}/, '-')
return
end end
main_category = @categories[categories.first] path = ['', attributes[:section], post_date.year, ("%02d" % post_date.month), attributes[:slug], ''].join('/')
top_category = find_topmost_category(main_category)
if main_category == top_category # require 'pp'
puts "WARNING: Need a secondary category" # pp attributes
#TODO prompt for second category here
end
path = ['', 'articles', top_category[:slug], main_category[:slug], attributes[:slug], ''].join('/')
require 'pp'
pp attributes
puts path
# add_item(content, attributes, identifier) # add_item(content, attributes, identifier)
end end
@ -118,6 +126,10 @@ module Importer
def process_attachment(attachment) def process_attachment(attachment)
puts "Processing attachment" puts "Processing attachment"
url = get(attachment, 'guid')
end end
def add_item(content, attributes, identifier) def add_item(content, attributes, identifier)