private static IModuleList GetModules(BlogPostsSettings settings) => new ModuleList { { MarkdownPosts, new ModuleCollection { new ReadFiles(ctx => $"{settings.PostsPath.Invoke<string>(ctx)}/**/{{!_,}}*.md"), new Meta(WebKeys.EditFilePath, (doc, ctx) => doc.FilePath(Keys.RelativeFilePath)), new If(settings.ProcessIncludes, new Include()), new FrontMatter(new Yaml.Yaml()), new Shortcodes(true), new Execute(ctx => new Markdown.Markdown() .UseConfiguration(settings.MarkdownConfiguration.Invoke <string>(ctx)) .UseExtensions(settings.MarkdownExtensionTypes.Invoke <IEnumerable <Type> >(ctx)) .PrependLinkRoot(settings.PrependLinkRoot.Invoke <bool>(ctx))) } }, { RazorPosts, new Concat { new ReadFiles(ctx => $"{settings.PostsPath.Invoke<string>(ctx)}/{{!_,!index,}}*.cshtml"), new Meta(WebKeys.EditFilePath, (doc, ctx) => doc.FilePath(Keys.RelativeFilePath)), new If(settings.ProcessIncludes, new Include()), new FrontMatter(new Yaml.Yaml()), new Shortcodes(true) } }, { WriteMetadata, new Excerpt() }, { Published, new ModuleCollection { new If( (doc, ctx) => doc.ContainsKey(settings.PublishedKey) && ctx.TryParseInputDateTime(doc.String(settings.PublishedKey), out _), new Meta("FrontMatterPublished", (doc, ctx) => true)) // Record whether the publish date came from front matter .Else( new Meta(settings.PublishedKey, (doc, ctx) => { DateTime published; if (doc.String(Keys.SourceFileName).Length >= 10 && ctx.TryParseInputDateTime(doc.String(Keys.SourceFileName).Substring(0, 10), out published)) { return(published); } Common.Tracing.Trace.Warning($"Could not parse published date for {doc.SourceString()}."); return(null); })), new Where((doc, ctx) => { if (!doc.ContainsKey(settings.PublishedKey) || doc.Get(settings.PublishedKey) == null) { Common.Tracing.Trace.Warning($"Skipping {doc.SourceString()} due to not having {settings.PublishedKey} metadata"); return(false); } if (doc.Get <DateTime>(settings.PublishedKey) > DateTime.Now) { Common.Tracing.Trace.Warning($"Skipping {doc.SourceString()} due to having {settings.PublishedKey} metadata of {doc.Get<DateTime>(settings.PublishedKey)} in the future (current date and time is {DateTime.Now})"); return(false); } return(true); }) } }, { RelativeFilePath, new Meta(Keys.RelativeFilePath, (doc, ctx) => { DateTime published = doc.Get <DateTime>(settings.PublishedKey); string fileName = doc.Bool("FrontMatterPublished") ? doc.FilePath(Keys.SourceFileName).ChangeExtension("html").FullPath : doc.FilePath(Keys.SourceFileName).ChangeExtension("html").FullPath.Substring(11); return(settings.IncludeDateInPostPath.Invoke <bool>(ctx) ? $"{settings.PostsPath.Invoke<string>(ctx)}/{published:yyyy}/{published:MM}/{fileName}" : $"{settings.PostsPath.Invoke<string>(ctx)}/{fileName}"); }) }, { OrderByPublished, new OrderBy((doc, ctx) => doc.Get <DateTime>(settings.PublishedKey)).Descending() } };
/// <summary> /// Creates the pipeline. /// </summary> /// <param name="name">The name of this pipeline.</param> /// <param name="settings">The settings for the pipeline.</param> public BlogPosts(string name, BlogPostsSettings settings) : base(name, GetModules(settings)) { }