From 01966e833d9fd8844b22d88ef262fc906842fba7 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Tue, 3 Dec 2024 18:46:09 +0100 Subject: [PATCH] Add livereload to live mode --- src/docs-builder/Http/DocumentationWebHost.cs | 8 ++++++++ src/docs-builder/docs-builder.csproj | 1 + 2 files changed, 9 insertions(+) diff --git a/src/docs-builder/Http/DocumentationWebHost.cs b/src/docs-builder/Http/DocumentationWebHost.cs index 889d654..391fcd1 100644 --- a/src/docs-builder/Http/DocumentationWebHost.cs +++ b/src/docs-builder/Http/DocumentationWebHost.cs @@ -12,6 +12,7 @@ using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; +using Westwind.AspNetCore.LiveReload; namespace Documentation.Builder.Http; @@ -30,6 +31,11 @@ public DocumentationWebHost(string? path, ILoggerFactory logger, IFileSystem fil { Collector = new ConsoleDiagnosticsCollector(logger) }; + builder.Services.AddLiveReload(s => + { + s.FolderToMonitor = context.SourcePath.FullName; + s.ClientFileExtensions = ".md"; + }); builder.Services.AddSingleton(_ => new ReloadableGeneratorState(sourcePath, null, context, logger)); builder.Services.AddHostedService(); builder.Services.AddSingleton(logger); @@ -39,10 +45,12 @@ public DocumentationWebHost(string? path, ILoggerFactory logger, IFileSystem fil SetUpRoutes(); } + public async Task RunAsync(Cancel ctx) => await _webApplication.RunAsync(ctx); private void SetUpRoutes() { + _webApplication.UseLiveReload(); _webApplication.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider(_staticFilesDirectory), diff --git a/src/docs-builder/docs-builder.csproj b/src/docs-builder/docs-builder.csproj index 3491361..d1788fb 100644 --- a/src/docs-builder/docs-builder.csproj +++ b/src/docs-builder/docs-builder.csproj @@ -27,6 +27,7 @@ +