diff --git a/YaeBlog.Core/Services/RendererService.cs b/YaeBlog.Core/Services/RendererService.cs index 2a7fbf6..20c377e 100644 --- a/YaeBlog.Core/Services/RendererService.cs +++ b/YaeBlog.Core/Services/RendererService.cs @@ -29,8 +29,7 @@ public class RendererService(ILogger logger, logger.LogInformation("Render essays start."); List contents = await essayScanService.ScanAsync(); - IEnumerable preProcessedContents = - PreProcess(contents); + IEnumerable preProcessedContents = await PreProcess(contents); List essays = []; await Task.Run(() => @@ -59,23 +58,14 @@ public class RendererService(ILogger logger, ConcurrentBag postProcessEssays = []; Parallel.ForEach(essays, essay => { - - BlogEssay newEssay = new() - { - Title = essay.Title, - FileName = essay.FileName, - Description = essay.Description, - WordCount = essay.WordCount, - PublishTime = essay.PublishTime, - HtmlContent = Markdown.ToHtml(essay.HtmlContent, markdownPipeline) - }; - newEssay.Tags.AddRange(essay.Tags); + BlogEssay newEssay = + essay.WithNewHtmlContent(Markdown.ToHtml(essay.HtmlContent, markdownPipeline)); postProcessEssays.Add(newEssay); logger.LogDebug("Render markdown file {}.", newEssay); }); - PostProcess(postProcessEssays); + await PostProcess(postProcessEssays); _stopwatch.Stop(); logger.LogInformation("Render finished, consuming {} s.", @@ -108,11 +98,11 @@ public class RendererService(ILogger logger, _postRenderProcessors.Add(processor); } - private IEnumerable PreProcess(IEnumerable contents) + private async Task> PreProcess(IEnumerable contents) { ConcurrentBag processedContents = []; - Parallel.ForEachAsync(contents, async (content, _) => + await Parallel.ForEachAsync(contents, async (content, _) => { foreach (var processor in _preRenderProcessors) { @@ -125,9 +115,9 @@ public class RendererService(ILogger logger, return processedContents; } - private void PostProcess(IEnumerable essays) + private async Task PostProcess(IEnumerable essays) { - Parallel.ForEachAsync(essays, async (essay, _) => + await Parallel.ForEachAsync(essays, async (essay, _) => { foreach (IPostRenderProcessor processor in _postRenderProcessors) {