Skip to content

Instantly share code, notes, and snippets.

@kevinpelgrims
Last active August 29, 2015 14:13
Show Gist options
  • Save kevinpelgrims/c11482eb8a8f9c15a950 to your computer and use it in GitHub Desktop.
Save kevinpelgrims/c11482eb8a8f9c15a950 to your computer and use it in GitHub Desktop.
LINQPad export script from Funnelweb to Jekyll
<Query Kind="Program">
</Query>
void Main()
{
var posts = Entries.Select(entry =>
new {
FileName = FormatFileName(entry.Name, entry.LatestRevisionFormat),
Content = FormatFileContent(entry.Title, entry.Published, FormatTags(entry.TagsCommaSeparated), entry.Body)
}
);
posts.Dump();
string exportDir = @"C:\fw_export\";
if (!Directory.Exists(exportDir))
{
Directory.CreateDirectory(exportDir);
}
foreach (var post in posts)
{
var path = exportDir + post.FileName;
File.WriteAllText(path, post.Content);
}
}
public String FormatFileName(String name, String format)
{
return name.Replace("/","-") + "." + format.ToLower();
}
public String FormatTags(String tags)
{
// Putting the tags into a YAML list.
// This requires them to be separated by a comma followed by a space,
// instead of just a comma.
return "[" + tags.Replace(",",", ") + "]";
}
public String FormatFileContent(String title, DateTime date, String tags, String content)
{
var sb = new StringBuilder();
sb.AppendLine("---");
sb.AppendLine("layout: post");
sb.AppendLine("title: \"" + title + "\"");
sb.AppendLine("date: " + date.ToString("yyyy-MM-dd HH:mm:ss"));
sb.AppendLine("categories: " + tags);
sb.AppendLine("comments: true");
sb.AppendLine("---");
sb.AppendLine(content);
return sb.ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment