private static void BuildTagsAndCategories(SiteContext context)
{
var tags = new Dictionary<string, List<Page>>();
var categories = new Dictionary<string, List<Page>>();
foreach (var post in context.Posts)
{
if (post.Tags != null)
{
foreach (var tagName in post.Tags)
{
if (tags.ContainsKey(tagName))
{
tags[tagName].Add(post);
}
else
{
tags.Add(tagName, new List<Page> { post });
}
}
}
if (post.Categories != null)
{
foreach (var categoryName in post.Categories)
{
AddCategory(categories, categoryName, post);
}
}
}
context.Tags = tags.Select(x => new Tag { Name = x.Key, Posts = x.Value }).OrderBy(x => x.Name).ToList();
context.Categories = categories.Select(x => new Category { Name = x.Key, Posts = x.Value }).OrderBy(x => x.Name).ToList();
}