private async Task ComposePages( Section section, IReadOnlyCollection <NavigationItem> menu, DocsSiteRouter router, DocsMarkdownService renderer, Func <Path, PipeReader, Task <PipeReader> > preprocessorPipe) { var pageComposer = new PageComposer(_site, section, _cache, _output, _uiBundle, renderer); foreach (var pageItem in section.ContentItems.Where(ci => IsPage(ci.Key, ci.Value))) { await pageComposer.ComposePage(pageItem.Key, pageItem.Value, menu, router, preprocessorPipe); } if (section.Type != "doc") { return; } // check if section has index page var indexPage = section.GetContentItem("index.md"); // if index page exists then don't generate it if (indexPage != null) { return; } // we need a redirect target var redirectToPage = section.IndexPage; await pageComposer.ComposeRedirectPage("index.html", redirectToPage); }
public PageComposer( Site site, Section section, IFileSystem cache, IFileSystem output, IUiBundle uiBundle, DocsMarkdownService renderer) { _site = site; _section = section; _cache = cache; _output = output; _uiBundle = uiBundle; _router = new DocsSiteRouter(site, section); _docsMarkdownService = renderer; }
private async Task <IReadOnlyCollection <NavigationItem> > ComposeMenu(Section section) { var items = new List <NavigationItem>(); foreach (var naviFileLink in section.Definition.Nav) { if (naviFileLink.Xref == null) { throw new NotSupportedException("External navigation file links are not supported"); } var xref = naviFileLink.Xref.Value; var targetSection = _site.GetSectionByXref(xref, section); if (targetSection == null) { throw new InvalidOperationException($"Invalid navigation file link {naviFileLink}. Section not found."); } var navigationFileItem = targetSection.GetContentItem(xref.Path); if (navigationFileItem == null) { throw new InvalidOperationException($"Invalid navigation file link {naviFileLink}. Path not found."); } await using var fileStream = await navigationFileItem.File.OpenRead(); using var reader = new StreamReader(fileStream); var text = await reader.ReadToEndAsync(); // override context so each navigation file is rendered in the context of the owning section var router = new DocsSiteRouter(_site, targetSection); var renderer = new DocsMarkdownService(new DocsMarkdownRenderingContext(_site, targetSection, router)); var builder = new NavigationBuilder(renderer, router); var fileItems = builder.Add(new string[] { text }) .Build(); items.AddRange(fileItems); } return(items); }
public NavigationBuilderFacts() { var source = Substitute.For <IContentSource>(); source.Version.Returns("TEST"); source.Path.Returns(new Path("")); var section = new Section(new ContentItem( source, null, null), new SectionDefinition() { Id = "sectionId" }, new Dictionary <Path, ContentItem>() { ["1-example.md"] = new ContentItem(source, null, null), ["1-Subsection/1-first.md"] = new ContentItem(source, null, null), ["1-Subsection/SubSubSection/1-first.md"] = new ContentItem(source, null, null), ["1-Subsection/SubSubSection/1-second.md"] = new ContentItem(source, null, null), ["1-Subsection/1-second.md"] = new ContentItem(source, null, null) }); var site = new Site( new SiteDefinition(), new Dictionary <string, Dictionary <string, Section> >() { ["TEST"] = new Dictionary <string, Section>() { [section.Id] = section } }); _router = new DocsSiteRouter(site, section); _mdService = new DocsMarkdownService( new DocsMarkdownRenderingContext(site, section, _router)); _sut = new NavigationBuilder(_mdService, null); }
public NavigationBuilder(DocsMarkdownService markdownService, DocsSiteRouter router) { _markdownService = markdownService; }