File tree Expand file tree Collapse file tree 3 files changed +38
-14
lines changed
tooling/docs-builder/Http Expand file tree Collapse file tree 3 files changed +38
-14
lines changed Original file line number Diff line number Diff line change @@ -147,25 +147,38 @@ public async Task<GenerationResult> GenerateAll(Cancel ctx)
147147 _logger . LogInformation ( $ "Generating links.json") ;
148148 var linkReference = await GenerateLinkReference ( ctx ) ;
149149
150- // Download diagram files in parallel
150+ await CreateDiagramCachedFiles ( ) ;
151+ CleanupUnusedDiagrams ( ) ;
152+
153+ // ReSharper disable once WithExpressionModifiesAllMembers
154+ return result with
155+ {
156+ Redirects = linkReference . Redirects ?? [ ]
157+ } ;
158+ }
159+
160+ /// <summary>
161+ /// Downloads diagram files in parallel from Kroki
162+ /// </summary>
163+ public async Task CreateDiagramCachedFiles ( )
164+ {
151165 var downloadedCount = await DocumentationSet . Context . DiagramRegistry . CreateDiagramCachedFiles ( _logger , DocumentationSet . Context . ReadFileSystem ) ;
152166 if ( downloadedCount > 0 )
153167 {
154168 _logger . LogInformation ( "Downloaded {DownloadedCount} diagram files from Kroki" , downloadedCount ) ;
155169 }
170+ }
156171
157- // Clean up unused diagram files
172+ /// <summary>
173+ /// Cleans up unused diagram files from the output directory
174+ /// </summary>
175+ public void CleanupUnusedDiagrams ( )
176+ {
158177 var cleanedCount = DocumentationSet . Context . DiagramRegistry . CleanupUnusedDiagrams ( DocumentationSet . OutputDirectory ) ;
159178 if ( cleanedCount > 0 )
160179 {
161180 _logger . LogInformation ( "Cleaned up {CleanedCount} unused diagram files" , cleanedCount ) ;
162181 }
163-
164- // ReSharper disable once WithExpressionModifiesAllMembers
165- return result with
166- {
167- Redirects = linkReference . Redirects ?? [ ]
168- } ;
169182 }
170183
171184 private async Task ProcessDocumentationFiles ( HashSet < string > offendingFiles , DateTimeOffset outputSeenChanges , Cancel ctx )
Original file line number Diff line number Diff line change 66using System . Text ;
77using Elastic . Documentation . Configuration . Diagram ;
88using Elastic . Markdown . Diagnostics ;
9+ using Elastic . Markdown . IO ;
910
1011namespace Elastic . Markdown . Myst . Directives . Diagram ;
1112
@@ -70,7 +71,12 @@ public override void FinalizeAndValidate(ParserContext context)
7071 }
7172
7273 // Register diagram for tracking, cleanup, and batch caching
74+ // Use the markdown file's scope directory for proper relative path resolution
7375 var outputDirectory = context . Build . DocumentationOutputDirectory . FullName ;
76+ if ( context . DocumentationFileLookup ( context . MarkdownSourcePath ) is MarkdownFile currentMarkdown )
77+ {
78+ outputDirectory = currentMarkdown . ScopeDirectory . FullName ;
79+ }
7480 context . DiagramRegistry . RegisterDiagramForCaching ( LocalSvgPath , EncodedUrl , outputDirectory ) ;
7581 }
7682
Original file line number Diff line number Diff line change 22// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33// See the LICENSE file in the project root for more information
44
5+ using System . IO ;
56using System . IO . Abstractions ;
67using System . Net ;
78using System . Runtime . InteropServices ;
@@ -153,12 +154,6 @@ await context.Response.WriteAsync(@"
153154 FileProvider = new EmbeddedOrPhysicalFileProvider ( Context ) ,
154155 RequestPath = "/_static"
155156 } )
156- . UseStaticFiles (
157- new StaticFileOptions
158- {
159- FileProvider = new PhysicalFileProvider ( Context . DocumentationOutputDirectory . FullName ) ,
160- RequestPath = ""
161- } )
162157 . UseRouting ( ) ;
163158
164159 _ = _webApplication . MapGet ( "/" , ( ReloadableGeneratorState holder , Cancel ctx ) =>
@@ -258,6 +253,16 @@ private static async Task<IResult> ServeDocumentationFile(ReloadableGeneratorSta
258253 if ( s == "index.md" )
259254 return Results . Redirect ( generator . DocumentationSet . MarkdownFiles . First ( ) . Url ) ;
260255
256+ // Check for cached SVG files (e.g., generated diagrams) in the output directory
257+ if ( Path . GetExtension ( slug ) . Equals ( ".svg" , StringComparison . OrdinalIgnoreCase ) )
258+ {
259+ var svgPath = Path . Combine ( generator . DocumentationSet . OutputDirectory . FullName , slug . TrimStart ( '/' ) ) ;
260+ if ( File . Exists ( svgPath ) )
261+ {
262+ return Results . File ( svgPath , "image/svg+xml" ) ;
263+ }
264+ }
265+
261266 if ( ! generator . DocumentationSet . FlatMappedFiles . TryGetValue ( "404.md" , out var notFoundDocumentationFile ) )
262267 return Results . NotFound ( ) ;
263268
You can’t perform that action at this time.
0 commit comments