@@ -23,10 +23,15 @@ private async Task<string> RenderNavigation(MarkdownFile markdown, Cancel ctx =
2323
2424 private string ? _renderedNavigation ;
2525
26- public async Task < string > RenderLayout ( MarkdownFile markdown , Cancel ctx = default )
26+ public static async Task < string > RenderPageHtml ( MarkdownFile markdown , Cancel ctx = default )
2727 {
2828 var document = await markdown . ParseFullAsync ( ctx ) ;
2929 var html = MarkdownFile . CreateHtml ( document ) ;
30+ return html ;
31+ }
32+
33+ public async Task < string > RenderLayout ( MarkdownFile markdown , string markdownHtml , Cancel ctx = default )
34+ {
3035 await DocumentationSet . Tree . Resolve ( ctx ) ;
3136 _renderedNavigation ??= await RenderNavigation ( markdown , ctx ) ;
3237
@@ -42,7 +47,7 @@ public async Task<string> RenderLayout(MarkdownFile markdown, Cancel ctx = defau
4247 {
4348 Title = markdown . Title ?? "[TITLE NOT SET]" ,
4449 TitleRaw = markdown . TitleRaw ?? "[TITLE NOT SET]" ,
45- MarkdownHtml = html ,
50+ MarkdownHtml = markdownHtml ,
4651 PageTocItems = [ .. markdown . TableOfContents . Values ] ,
4752 Tree = DocumentationSet . Tree ,
4853 CurrentDocument = markdown ,
@@ -57,6 +62,34 @@ public async Task<string> RenderLayout(MarkdownFile markdown, Cancel ctx = defau
5762 return await slice . RenderAsync ( cancellationToken : ctx ) ;
5863 }
5964
65+
66+ public async Task < string > RenderPage ( MarkdownFile markdown , string markdownHtml , Cancel ctx = default )
67+ {
68+ var previous = DocumentationSet . GetPrevious ( markdown ) ;
69+ var next = DocumentationSet . GetNext ( markdown ) ;
70+
71+ var remote = DocumentationSet . Context . Git . RepositoryName ;
72+ var branch = DocumentationSet . Context . Git . Branch ;
73+ var path = Path . Combine ( DocumentationSet . RelativeSourcePath , markdown . RelativePath ) ;
74+ var editUrl = $ "https://github.com/elastic/{ remote } /edit/{ branch } /{ path } ";
75+
76+ var slice = Page . Create ( new MainViewModel
77+ {
78+ Title = markdown . Title ?? "[TITLE NOT SET]" ,
79+ TitleRaw = markdown . TitleRaw ?? "[TITLE NOT SET]" ,
80+ MarkdownHtml = markdownHtml ,
81+ PageTocItems = [ .. markdown . TableOfContents . Values ] ,
82+ CurrentDocument = markdown ,
83+ PreviousDocument = previous ,
84+ NextDocument = next ,
85+ UrlPathPrefix = markdown . UrlPathPrefix ,
86+ Applies = markdown . YamlFrontMatter ? . AppliesTo ,
87+ GithubEditUrl = editUrl ,
88+ AllowIndexing = DocumentationSet . Context . AllowIndexing && ! markdown . Hidden
89+ } ) ;
90+ return await slice . RenderAsync ( cancellationToken : ctx ) ;
91+ }
92+
6093 public async Task WriteAsync ( IFileInfo outputFile , MarkdownFile markdown , Cancel ctx = default )
6194 {
6295 if ( outputFile . Directory is { Exists : false } )
@@ -78,9 +111,15 @@ public async Task WriteAsync(IFileInfo outputFile, MarkdownFile markdown, Cancel
78111 ? Path . GetFileNameWithoutExtension ( outputFile . Name ) + ".html"
79112 : Path . Combine ( dir , "index.html" ) ;
80113 }
114+ var mainPath = Path . ChangeExtension ( path , ".main.html" ) ;
115+
116+ var pageHtml = await RenderPageHtml ( markdown , ctx ) ;
81117
82- var rendered = await RenderLayout ( markdown , ctx ) ;
118+ var rendered = await RenderLayout ( markdown , pageHtml , ctx ) ;
83119 await writeFileSystem . File . WriteAllTextAsync ( path , rendered , ctx ) ;
120+
121+ var renderedPage = await RenderPage ( markdown , pageHtml , ctx ) ;
122+ await writeFileSystem . File . WriteAllTextAsync ( mainPath , renderedPage , ctx ) ;
84123 }
85124
86125}
0 commit comments