public async Task <ContentItem> ComposePage( Path relativePath, ContentItem page, IReadOnlyCollection <NavigationItem> menu, DocsSiteRouter router, Func <Path, PipeReader, Task <PipeReader> > preprocessorPipe) { var(partialHtmlPage, frontmatter) = await ComposePartialHtmlPage( relativePath, page, router, preprocessorPipe); if (frontmatter == null) { frontmatter = new PageFrontmatter { Template = _uiBundle.DefaultTemplate } } ; var fullHtmlPage = await ComposeFullHtmlPage(partialHtmlPage, frontmatter, menu); return(fullHtmlPage); }
public PageRenderingContext(Site site, Section section, IReadOnlyCollection <NavigationItem> menu, PageFrontmatter page, string pageHtml) { Site = site; Section = section; Menu = menu; Page = page; PageHtml = pageHtml; }
private async Task <ContentItem> ComposeFullHtmlPage( ContentItem partialHtmlPage, PageFrontmatter frontmatter, IReadOnlyCollection <NavigationItem> menu) { // open file streams await using var inputStream = await partialHtmlPage.File.OpenRead(); using var reader = new StreamReader(inputStream); var partialPageHtml = await reader.ReadToEndAsync(); // create output dir for page await _output.GetOrCreateDirectory(partialHtmlPage.File.Path.GetDirectoryPath()); // create output file var outputFile = await _output.GetOrCreateFile(partialHtmlPage.File.Path); if (string.IsNullOrEmpty(frontmatter.Title)) { frontmatter.Title = outputFile.Path.GetFileName().ChangeExtension(null); } var fullPageHtml = _uiBundle.GetPageRenderer(frontmatter.Template, _router) .Render(new PageRenderingContext( _site, _section, menu, frontmatter, partialPageHtml )); await using var outputStream = await outputFile.OpenWrite(); await using var writer = new StreamWriter(outputStream); await writer.WriteAsync(fullPageHtml); return(partialHtmlPage.WithFile(outputFile)); }