private Page CreatePage(string file, string childPagesRootFolder) { var fileContent = File.ReadAllText(file); var postContent = Regex.Split(fileContent, "---"); var metadata = postContent[1]; var content = postContent[2]; var title = metadata.GetTagsValue("title"); var permalink = metadata.GetTagsValue("permalink"); var description = metadata.GetTagsValue("description"); var tags = metadata.GetTagsValue("tags").Split(',').Select(tag => tag.Trim()).ToList(); var layout = metadata.GetTagsValue("layout"); var layoutFile = Path.Combine(configuration.TemplateRootFolder, layout); var time = DateTime.Parse(metadata.GetTagsValue("time"), CultureInfo.InvariantCulture); var post = new Page { Description = description, Location = Path.Combine(@"\", relativePathPrefix, childPagesRootFolder, permalink).Replace(@"\", @"/"), Title = title, Time = time, TagNames = tags, Slurg = permalink, LayoutFile = layoutFile, }; var options = new MarkdownOptions { AutoHyperlink = true, AutoNewlines = true, EmptyElementSuffix = "/>", EncodeProblemUrlCharacters = false, LinkEmails = true, StrictBoldItalic = true }; var parser = new Markdown(options); post.Content = parser.Transform(content.Trim()); foreach (var tag in post.TagNames) { if (allTags.ContainsKey(tag)) { allTags[tag].Pages.Add(post); continue; } var value = new Tag { Name = tag, Pages = new List<Page> { post } }; allTags.Add(tag, value); } return post; }
private Page CreatePage(string file, string childPagesRootFolder) { var fileContent = File.ReadAllText(file); var postContent = Regex.Split(fileContent, "---"); var metadata = postContent[1]; var content = postContent[2]; var meta = metadata.GetTags(); var title = meta["title"]; var permalink = meta["permalink"]; var description = meta["description"]; var tags = meta["tags"].Split(',').Select(tag => tag.Trim()).ToList(); var layout = meta.ContainsKey("layout") ? meta["layout"] : defaultLayoutFile; if (string.IsNullOrWhiteSpace(layout)) throw new ArgumentNullException("Layout", "No layout set either in the post or in the configuration."); var layoutFile = Path.Combine(configuration.TemplateRootFolder, layout); DateTime time; if (!DateTime.TryParse(meta["time"], CultureInfo.InvariantCulture, DateTimeStyles.None, out time)) { var parsingTimeFailedPage = string.Format("Parsing time failed. Page {0}, Date {1}", file, meta["time"]); throw new Exception(parsingTimeFailedPage); } var post = new Page { Description = description, Location = Path.Combine(@"\", relativePathPrefix, childPagesRootFolder, permalink).Replace(@"\", @"/"), Title = title, Time = time, TagNames = tags, Slurg = permalink, LayoutFile = layoutFile, ParentPage = Path.Combine("/", relativePathPrefix, childPagesRootFolder) }; var options = new MarkdownOptions { AutoHyperlink = true, AutoNewlines = true, EmptyElementSuffix = "/>", EncodeProblemUrlCharacters = false, LinkEmails = true, StrictBoldItalic = true }; var parser = new Markdown(options); post.Content = parser.Transform(content.Trim()); foreach (var tag in post.TagNames) { if (allTags.ContainsKey(tag)) { allTags[tag].Pages.Add(post); continue; } var value = new Tag { Name = tag, Pages = new List<Page> { post } }; allTags.Add(tag, value); } return post; }
/// <summary> /// Create a new Markdown instance and set the options from the MarkdownOptions object. /// </summary> public Markdown(MarkdownOptions options) { _autoHyperlink = options.AutoHyperlink; _autoNewlines = options.AutoNewlines; _emptyElementSuffix = options.EmptyElementSuffix; _encodeProblemUrlCharacters = options.EncodeProblemUrlCharacters; _linkEmails = options.LinkEmails; _strictBoldItalic = options.StrictBoldItalic; }