Created
March 10, 2010 06:47
-
-
Save sethladd/327600 to your computer and use it in GitHub Desktop.
Migrate from Wordpress to Blogger
This file contains hidden or 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 'nokogiri' | |
require 'httparty' | |
export = Nokogiri::XML(File.new(ARGV[0])) | |
export.root.xpath("//item/link").each do |node| | |
begin | |
# do this the hard way because no way to get final URI after redirects otherwise | |
request = HTTParty::Request.new(Net::HTTP::Head, node.text, {}) | |
response = request.perform | |
unless response.code == 200 | |
puts "#{request.path} does not work (was #{node.text})" | |
end | |
rescue URI::InvalidURIError => e | |
puts "URL: #{node.text} is invalid?" | |
end | |
end |
This file contains hidden or 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
<VirtualHost *> | |
ServerName blog.semergence.com | |
DocumentRoot /var/www/blog.semergence.com | |
ErrorLog /var/log/apache2/blog.semergence.com-error.log | |
CustomLog /var/log/apache2/blog.semergence.com-access.log common | |
ErrorDocument 404 /redirect-to-blogger.php | |
RewriteEngine On | |
RewriteRule ^/$ http://blog.sethladd.com/ [R=301] | |
RewriteRule ^/feed http://blog.sethladd.com/feeds/posts/default [R=301] | |
RewriteRule ^/category - [G] | |
<Directory /var/www/blog.semergence.com> | |
Order allow,deny | |
Allow From All | |
AllowOverride All | |
</Directory> | |
</VirtualHost> |
This file contains hidden or 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
<?php | |
$pattern = "{^/(\d{4})/(\d{2})/\d{2}\/(.*)/$}"; | |
preg_match($pattern, $_SERVER['REDIRECT_URL'], $matches); | |
if (empty($matches)) { | |
header("HTTP/1.1 404 Not Found"); | |
exit(); | |
} | |
$year = $matches[1]; | |
$month = $matches[2]; | |
$slug = $matches[3]; | |
// blogger removes common words | |
function filter($val) { | |
switch ($val) { | |
case 'the': | |
case 'a': | |
case 'an': | |
case '.': | |
return false; | |
default: | |
return true; | |
} | |
} | |
$slug = implode('-', array_filter(explode('-', $slug), "filter")); | |
// blogger only has less than 39 characters | |
while (strlen($slug) > 39) { | |
$slug = substr($slug, 0, strrpos($slug, '-')); | |
} | |
// blogger doesn't like underscores | |
$slug = str_replace('_', '', $slug); | |
$redirect = 'http://blog.sethladd.com/'.$year.'/'.$month.'/'.$slug.'.html'; | |
header("HTTP/1.1 301 Moved Permanently"); | |
header('Location: ' . $redirect); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is just the app what I need but I have no idea how to get it running. Can you please advise, thank you.