mirror of
https://github.com/wezm/wezm.net.git
synced 2024-12-18 18:29:54 +00:00
Generate the new path for the post
This commit is contained in:
parent
d5f2816204
commit
cee8eba9ce
1 changed files with 45 additions and 5 deletions
|
@ -9,6 +9,32 @@ module Importer
|
||||||
@export_file = File.open(wordpress_export_path)
|
@export_file = File.open(wordpress_export_path)
|
||||||
@export = Nokogiri::XML(@export_file)
|
@export = Nokogiri::XML(@export_file)
|
||||||
@site = Nanoc3::Site.new(nanoc_site_path)
|
@site = Nanoc3::Site.new(nanoc_site_path)
|
||||||
|
|
||||||
|
load_categories
|
||||||
|
load_tags
|
||||||
|
end
|
||||||
|
|
||||||
|
def load_categories
|
||||||
|
@categories = {}
|
||||||
|
@export.xpath('//rss/channel/wp:category').each do |category|
|
||||||
|
name = get(category, 'wp:cat_name')
|
||||||
|
parent = get(category, 'wp:category_parent')
|
||||||
|
parent = nil if parent.empty?
|
||||||
|
@categories[name] = {
|
||||||
|
:slug => get(category, 'wp:category_nicename'),
|
||||||
|
:name => name,
|
||||||
|
:parent => parent
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def load_tags
|
||||||
|
@tags = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
def find_topmost_category(category)
|
||||||
|
return category if category[:parent].nil?
|
||||||
|
find_topmost_category(@categories[category[:parent]])
|
||||||
end
|
end
|
||||||
|
|
||||||
def run
|
def run
|
||||||
|
@ -52,10 +78,11 @@ module Importer
|
||||||
post.css('category[domain=category]').each do |category|
|
post.css('category[domain=category]').each do |category|
|
||||||
categories << category.text
|
categories << category.text
|
||||||
end
|
end
|
||||||
|
categories.uniq!
|
||||||
|
|
||||||
attributes = {
|
attributes = {
|
||||||
:tags => tags.uniq,
|
:tags => tags.uniq,
|
||||||
:categories => categories.uniq,
|
:categories => categories,
|
||||||
:permalink => get(post, 'link'),
|
:permalink => get(post, 'link'),
|
||||||
:status => get(post, 'wp:status'),
|
:status => get(post, 'wp:status'),
|
||||||
:slug => get(post, 'wp:post_name'),
|
:slug => get(post, 'wp:post_name'),
|
||||||
|
@ -63,13 +90,26 @@ module Importer
|
||||||
:post_date => get(post, 'wp:post_date_gmt'),
|
:post_date => get(post, 'wp:post_date_gmt'),
|
||||||
}
|
}
|
||||||
|
|
||||||
unless attributes[:slug]
|
if attributes[:slug].empty?
|
||||||
puts "Error post #{post_id} has no slug"
|
puts "WARNING: Error post #{attributes[:post_id]} has no slug"
|
||||||
|
#TODO prompt for slug or derive one from the title here
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
path = "/articles/#{slug}"
|
main_category = @categories[categories.first]
|
||||||
add_item(content, attributes, identifier)
|
top_category = find_topmost_category(main_category)
|
||||||
|
|
||||||
|
if main_category == top_category
|
||||||
|
puts "WARNING: Need a secondary category"
|
||||||
|
#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)
|
||||||
end
|
end
|
||||||
|
|
||||||
def process_page(page)
|
def process_page(page)
|
||||||
|
|
Loading…
Reference in a new issue