public static void WriteToFiles(string directory, Topic topLevel)
{
if (!FileSystem.DirectoryExists(directory))
{
FileSystem.CreateDirectory(directory);
}
var file = directory.AppendPath("index.md");
WriteTopicFile(file, topLevel);
WriteOrderFile(directory, topLevel);
topLevel.Children.Each(child =>
{
var key = child.KeyWithinParent;
if (child.Children.Any())
{
WriteToFiles(directory.AppendPath(key), child);
}
else
{
var childFile = directory.AppendPath(key + ".md");
WriteTopicFile(childFile, child);
}
});
}