www.arareko.net

"I wouldn't last 30 minutes climbing solo."

- Bradford Washburn

Archive for March, 2010

Sunday, March 28th, 2010

My Blogger to WordPress migration

Some years ago (around 2006), I experienced problems with the Blogger service while publishing via sFTP to my own domain. After reviewing some of the most-known CMS options I started working on migrating this blog to the WordPress software. My work back then consisted mostly on porting the look & feel of the blog to the WordPress templating system. Eventually, Blogger fixed their sFTP service and I no longer had the immediate need of completing the project, thus saving it for later. This worked fine until Blogger announced at the beginning of this year the deprecation of their FTP (and sFTP) protocols for publishing to non-blogspot.com domains.

Finding a solution was imminent this time and since I didn’t want to take the Blogger’s custom domains suggested approach, my only option was to finish the pending work with WordPress. After reading a bunch of how-tos and tutorials around the web I opted to use my own approach to get the job done. As many tutorials point out, the main issue with any Blogger to WordPress migration is maintaining the original permalinks from old posts as well as to properly handle redirects to the blog’s previous monthly archives, so links from search engines could continue to work.

Some tutorials suggest using the Blogger importer included in WordPress, with an extra plugin to ‘maintain Blogger permalinks’ for the imported posts. The importer, however, proved to be bad at the time of importing post’s comments, as it’s only able to import 50 comments at the most (for the whole blog!). For blogs with a lot of traffic and user comments (not my case) this isn’t a promising solution.

Other tutorials suggest using the blogger2wordpress utility to transform a Blogger export file into a WordPress extended RSS (WXR) file. The downside with this approach is that WordPress generates new permalinks for the imported posts, which aren’t exactly the same as those from Blogger and there is no plugin available to ‘maintain’ them as they were.

This is where a little Perl scripting came to the rescue. After taking a closer look to the WXR file generated by the blogger2wordpress service, I figured out how the WordPress-included WXR importer creates the new permalinks from the contents in the file: it takes the post titles and transforms them into a permalink structure. Fortunately, the WXR file contains the original Blogger permalinks for each post, so all I had to do was to replace the contents for each post title with the corresponding substring from the Blogger permalink and voila!, the WXR file was ready to be imported into the WordPress database and nothing else was needed to ‘maintain’ the original permalinks.

I think the script can be useful for those in a similar case who have access to a Perl interpreter, so here it is:

#!/usr/bin/perl -w
use strict;

my $file = shift;

open(F, "+<", $file)    or die "can't read $file: $!";
my $out = '';
$/ = "<item>";
while (<F>) {
  /\<link\>http\:\/\/.+\/\d{4}\/\d{2}\/(.+)\.html\<\/link\>/;
  if ($1) {
    my $slug = $1;
    s/post_name\>.+\</"post_name\>".$slug."\<"/eg;
  }
  $out .= $_;
}
seek(F, 0, 0)           or die "can't seek to start of $file: $!";
print F $out            or die "can't print to $file: $!";
truncate(F, tell(F))    or die "can't truncate $file: $!";
close(F)                or die "can't close $file: $!";

Save this code into a file such as replace_blog_permalinks.pl and change its permissions to make it executable. Then all you need to do to fix your blogger2wordpress WXR file is to run from the command line:

$ replace_blog_permalinks.pl YOUR_WXR_FILE.xml

I imported the resulting file into WordPress and once I had all of my posts and comments with the original permalinks in place, the rest of the setup consisted of setting up proper redirection to the blog archives: I created an archive/ directory under the blog/ directory (where I installed the WordPress files) and placed this into a .htaccess file inside of it:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /blog/archive/
  RewriteRule ^([0-9]+)_([0-9]+)_([0-9]+)_archive\.html$ /blog/$1/$2/ [R=301,L]
</IfModule>

I also setup proper redirection to the new feed locations as well as the usual WordPress rewrite rules to use custom permalinks for new posts. This was placed in a .htaccess file inside the /blog directory:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /blog
  RewriteRule ^atom\.xml$ /blog/feed/atom [R=301,L]
  RewriteRule ^rss\.xml$ /blog/feed [R=301,L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /blog/index.php [L]
</IfModule>

The last step in the WordPress configuration was to put the following custom structure into the Permalink Settings in the WordPress dashboard: /%year%/%monthnum%/%postname%.html

An extra step in my case was to copy the templates I ported years ago into the proper directory under the WordPress installation and use the theme manager to switch to my custom design. The result is what you see now in this page: my blog (and website) in exactly the same form as it has always been and with a new and powerful blogging engine underneath it. I hope my experience with this becomes useful to you

Saturday, March 13th, 2010

Running with the Tarahumara

Last weekend Beto and I traveled to the Sierra Tarahumara to run Caballo Blanco’s Copper Canyon Ultramarathon. We flew from Mexico City to Los Mochis on Thursday then rode the Chepe train at first hour on Friday’s morning. Last time I was in the Sierra was a little more than 10 years ago. This time we had the opportunity to travel in the Eastern direction of the train’s route, passing along places I haven’t seen before in my previous trips.

We arrived to Bahuichivo around 3 p.m. and the truck we previously hired was already there waiting to take us deep down into the canyons and to the town of Urique. We were in the middle of the Sierra and very happy of the great time we were having. Once at Urique we found a hotel room to drop our things and headed out for a short hike around town. We encountered a lot of people from the US which arrived earlier in the week to hike in the canyons as well as to run the race with the Tarahumaras.

Saturday was all about resting, eating and having fun in Urique. We attended the race briefing in the afternoon, where we got a real idea of the amount of people that would be running the race. A little bit more than 300 runners showed up, roughly consisting of 70 foreigners, 30 nationals and 200+ Tarahumaras. The weather forecast for the race was a good one, with cloudy skies for most part of the day and some probability of rain. Compared to last year’s weather conditions (35-40º C), this was going to be a totally different game.

Race begun at 6:30 a.m. on Sunday, Beto and I shook hands and wished luck for what was going to be a strenuous but fun adventure. The Tarahumaras immediately took the lead, demonstrating that even though most of them run in huaraches their genes have evolved over centuries for this kind of activity. The first loop in the course was of 18+ miles and consisted of running up river to the little village of Guadalupe and back, then turn right just before returning to Urique and climb uphill along a single track trail that headed to Mesa Naranjo. The views at all times were amazing and the weather remained good for most of the morning. A long and winding dirt road took me back to Urique after 5 hours of running, Beto was about 1 hour behind me at this point.

I grabbed more energy gels and a bar from my dropbag and went out of town in down river direction. A long and mostly flat dirt road lead us along the river shore. A little bit before arriving to the town of Guapalayna I saw the first Tarahumara runners coming back from the turnaround point. While I was completing my 22nd mile these guys were reaching their 34th, 12 miles ahead of me and still going very strong. It was obvious that 2 different races were taking place, while they struggled to arrive in the first places and win a respectable amount of money, I was running comfortably and enjoying the beauty of the Sierra.

A hanging bridge took me out of the dirt road and into a single track trail that consisted of a very strenuous climb towards Los Alisos, a remote ranch in the middle of the mountain. Most of the runners were coming back at this point, the sun was out and the temperature started to rise considerably. The trail was beautiful and a little bit exposed, the hills were so steep at some places that a bad step could turn into a nasty fall through the woods. A little bit before arriving to Los Alisos it started to rain, it lasted for a few minutes but was good enough to cool me down a little bit. I checked into the aid station, got the proof bracelet and ate some fruits. I ran for most of the return, then found Beto at the very bottom of the climb, he had some problems with a long-time injured knee but was still in the game. I provided some advice on the beautiful trail ahead of him then wished luck and continued running.

Back in Guapalayna my feet plants started to hurt, I developed huge blisters because of getting wet shoes after having crossed some rivers, shoes weren’t drying due to the mostly shady day. I walked for most of the flat dirt road as its gravel wasn’t helping much to relieve the pain. I got back to Urique at 5 p.m., I had 40 miles traveled and didn’t feel like completing the full 50-mile race. The last 10 miles were an out and back short loop in the previously run Guadalupe dirt road so there was nothing new to see for the rest of the race. I opted to call it a good day in the canyons and ended my journey there. I wasn’t tired, only aching from my blistered feet but extremely happy, I logged 10 hours and 30 minutes. Beto finished the 40 miles 3 hours after I did, he exceeded the race cut-off but, just as me, wanted to take things easily and enjoy the day.

We rode the van back to Bahuichivo on Monday morning, then catched the afternoon train to Los Mochis. On Thursday morning we were flying back to Mexico City, extremely happy of the adventure we just had and already daydreaming about future projects. Even though it was a short time in the Sierra, we were very pleased of having had the opportunity to run side by side with the legendary Tarahumaras. At least for a couple of hours…

Rest of the pictures are here.