public BlogPost Build(PostData data) { var title = UrlSlug.Slugify(data.Title); var html = _markdownParser.ToTrustedHtml(data.Markdown); string?introHtml = null; var mainSectionIndex = data.Markdown.IndexOf("\n[//]: # (Main Section)", StringComparison.Ordinal); if (mainSectionIndex > -1) { var introMarkdown = data.Markdown.Substring(0, mainSectionIndex); introHtml = _markdownParser.ToTrustedHtml(introMarkdown); } var pageMetadata = _pageMetadataBuilder.Build(data.PageMetaData); var result = new BlogPost( data.FileName, data.Title, data.Author, data.PublishedOn, data.IsPublished, data.IsListed, title, html, introHtml, pageMetadata ); return(result); }
public async Task <BlogPost?> GetPostAsync(DateTime published, string slug) { // Allow users to access posts with direct links, even if they are not listed or are future posts // Useful for asking friends to have a look at something. // We do respect the "IsPublished" flag though. await foreach (var postData in _postRepository.GetPostsByDateAsync(published)) { if (postData.IsPublished) { var postSlug = UrlSlug.Slugify(postData.Title); if (string.Equals(postSlug, slug, StringComparison.OrdinalIgnoreCase)) { var post = _postBuilder.Build(postData); return(post); } } } _logger.LogDebug("Post with date {date} and slug {slug} not found", published, slug); return(null); }