Created
April 30, 2011 08:41
-
-
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
This file contains 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
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