Skip to content

Instantly share code, notes, and snippets.

@mikeminutillo
Created April 30, 2011 08:41
Show Gist options
  • Save mikeminutillo/949535 to your computer and use it in GitHub Desktop.
Save mikeminutillo/949535 to your computer and use it in GitHub Desktop.
Quick Tool to update the postName for each entry in my converted BlogML Blogger export file
var inputFile = @"whatever.xml";
var outputFile = @"whatever.updated.xml";
BlogMLBlog blog;
using (var reader = new StreamReader(inputFile))
blog = BlogMLSerializer.Deserialize(reader);
var usedNames = new List<string>();
foreach(var post in blog.Posts.OrderBy(p => p.DateCreated))
{
var newName = Regex.Replace(post.Title.ToLower().Replace("'", "").Replace("c#", "c-sharp").Replace("f#", "f-sharp").Replace(" .net", "-dot-net"), @"[^a-z0-9]+", "-").TrimStart('-').TrimEnd('-');
if(String.IsNullOrEmpty(newName))
newName = "unknown-post";
int i = 2;
while(usedNames.Contains(newName))
{
newName = newName + "-" + i++;
}
usedNames.Add(newName);
post.PostName = newName;
}
using(var writer = new StreamWriter(outputFile))
BlogMLSerializer.Serialize(writer, blog);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment