Skip to content

Commit 5cdbdaf

Browse files
authored
Ensure docs-builder builds to .artifacts/assembly/<content-source> and support a flag on serve-static to choose (#1241)
1 parent 8b69073 commit 5cdbdaf

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

src/tooling/docs-assembler/AssembleContext.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ public AssembleContext(
7474
var contentSource = Environment.ContentSource.ToStringFast(true);
7575
var defaultCheckoutDirectory = Path.Combine(Paths.WorkingDirectoryRoot.FullName, ".artifacts", "checkouts", contentSource);
7676
CheckoutDirectory = ReadFileSystem.DirectoryInfo.New(checkoutDirectory ?? defaultCheckoutDirectory);
77-
OutputDirectory = ReadFileSystem.DirectoryInfo.New(output ?? Path.Combine(".artifacts", "assembly"));
77+
var defaultOutputDirectory = Path.Combine(Paths.WorkingDirectoryRoot.FullName, ".artifacts", "assembly", contentSource);
78+
OutputDirectory = ReadFileSystem.DirectoryInfo.New(output ?? defaultOutputDirectory);
7879

7980

8081
}

src/tooling/docs-builder/Cli/Commands.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,15 @@ public async Task Serve(string? path = null, int port = 3000, Cancel ctx = defau
5050
/// Serve html files directly
5151
/// </summary>
5252
/// <param name="port">Port to serve the documentation.</param>
53+
/// <param name="contentSource">The content source to serve defaults to next</param>
5354
/// <param name="ctx"></param>
5455
[Command("serve-static")]
5556
[ConsoleAppFilter<CheckForUpdatesFilter>]
56-
public async Task ServeStatic(int port = 4000, Cancel ctx = default)
57+
public async Task ServeStatic(int port = 4000, string? contentSource = null, Cancel ctx = default)
5758
{
59+
contentSource ??= "next";
5860
AssignOutputLogger();
59-
var host = new StaticWebHost(port);
61+
var host = new StaticWebHost(port, contentSource);
6062
await host.RunAsync(ctx);
6163
await host.StopAsync(ctx);
6264
}

src/tooling/docs-builder/Http/StaticWebHost.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,18 @@ namespace Documentation.Builder.Http;
1717

1818
public class StaticWebHost
1919
{
20+
private readonly string _contentSource;
2021
private readonly WebApplication _webApplication;
2122

22-
public StaticWebHost(int port)
23+
public StaticWebHost(int port, string contentSource)
2324
{
24-
var builder = WebApplication.CreateSlimBuilder();
25+
_contentSource = contentSource;
26+
var contentRoot = Path.Combine(Paths.WorkingDirectoryRoot.FullName, ".artifacts", "assembly", _contentSource);
27+
28+
var builder = WebApplication.CreateBuilder(new WebApplicationOptions
29+
{
30+
ContentRootPath = contentRoot
31+
});
2532
DocumentationTooling.CreateServiceCollection(builder.Services, LogLevel.Warning);
2633

2734
_ = builder.Logging
@@ -49,14 +56,14 @@ private void SetUpRoutes()
4956
_ = _webApplication.MapGet("{**slug}", ServeDocumentationFile);
5057
}
5158

52-
private static async Task<IResult> ServeDocumentationFile(string slug, Cancel _)
59+
private async Task<IResult> ServeDocumentationFile(string slug, Cancel _)
5360
{
5461
// from the injected top level navigation which expects us to run on elastic.co
5562
if (slug.StartsWith("static-res/"))
5663
return Results.NotFound();
5764

5865
await Task.CompletedTask;
59-
var path = Path.Combine(Paths.WorkingDirectoryRoot.FullName, ".artifacts", "assembly");
66+
var path = Path.Combine(Paths.WorkingDirectoryRoot.FullName, ".artifacts", "assembly", _contentSource);
6067
var localPath = Path.Combine(path, slug.Replace('/', Path.DirectorySeparatorChar));
6168
var fileInfo = new FileInfo(localPath);
6269
var directoryInfo = new DirectoryInfo(localPath);

0 commit comments

Comments
 (0)