ailon's DevBlog: Development related stuff in my life

Porting Old BlogEngine.net Comments to Disqus

12/29/2011 10:45:36 AM

Yesterday I’ve finally managed to upgrade this blog to the latest version of BlogEngine.net. Let me know if you notice any issues related to that.

The process was smooth and easy. Except that I wanted to move commenting to Disqus at the same time. Enabling Disqus comments was easy too, but moving old comments up there was not.

First I found this method and tool. It looked like it worked at first but comments didn’t show up in Disqus. Then I figured that BE.net uses Permalink for Disqus URLs and this tool was using “friendly” link. So I modified what it was exporting and then it just started crashing when trying to upload comments to Disqus.

Then I found this method and tool. It takes standard export from BlogEngine.net in BlogML format, extracts comments from it and saves them in WRX format that can be imported into Disqus. Unfortunately it uses the same “friendly” URLs and BE uses permalinks as identifiers for Disqus threads. Obviously its possible to modify BE code to use the same URLs but it’s not future-proof (among other issues).

So finally I decided to make a small utility that would take WRX generated by the above mentioned tool and original BlogML and replaces “friendly” URLs with permalinks in the WRX. It’s very primitive and not flexible so I’m posting source here instead of binary.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace BlogML2WRXFix
{
class Program
{
static void Main(string[] args)
{
var wrx = XDocument.Load(args[0]);
var blogML = XDocument.Load(args[1]);
XNamespace blogMLNS = "http://www.blogml.com/2006/09/BlogML";
string hostPrefix = args[2];

var wrxItems = wrx.Descendants("item");

foreach (var wrxItem in wrxItems)
{
var linkNode = wrxItem.Descendants("link").First();
// URLs in my WRX included extra slash at the beginning
string linkUrl = linkNode.Value.Substring(1);
linkNode.Value = String.Format(hostPrefix + "post.aspx?id={0}", blogML.Descendants(blogMLNS + "post").First(f => f.Attribute("post-url").Value == linkUrl).Attribute("id").Value);
}

wrx.Save(args[0]);

Console.ReadLine();
}
}
}

It takes path to the WRX file as the first parameter, path to BlogML file as the second and host prefix to use for the output URLs (like http://devblog.ailon.org/) as the third.

Tags:

blog comments powered by Disqus
Copyright © 2003 - 2012 Alan Mendelevich
Powered by BlogEngine.NET 2.5.0.6