Skip to content

Commit

Permalink
Add livereload to live mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Mpdreamz committed Dec 3, 2024
1 parent d65070b commit 01966e8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/docs-builder/Http/DocumentationWebHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Westwind.AspNetCore.LiveReload;

namespace Documentation.Builder.Http;

Expand All @@ -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<ReloadableGeneratorState>(_ => new ReloadableGeneratorState(sourcePath, null, context, logger));
builder.Services.AddHostedService<ReloadGeneratorService>();
builder.Services.AddSingleton(logger);
Expand All @@ -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),
Expand Down
1 change: 1 addition & 0 deletions src/docs-builder/docs-builder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<PackageReference Include="Errata" Version="0.13.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0"/>
<PackageReference Include="Github.Actions.Core" Version="8.1.1"/>
<PackageReference Include="Westwind.AspNetCore.LiveReload" Version="0.5.0" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 01966e8

Please sign in to comment.