Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions Elastic.Documentation.Tooling/DocumentationTooling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@ public static ServiceProvider CreateServiceProvider(ref string[] args, Action<IS
var defaultLogLevel = LogLevel.Information;
ProcessCommandLineArguments(ref args, ref defaultLogLevel);

var services = new ServiceCollection()
var services = new ServiceCollection();
CreateServiceCollection(services, defaultLogLevel);
configure?.Invoke(services);
return services.BuildServiceProvider();
}

public static void CreateServiceCollection(IServiceCollection services, LogLevel defaultLogLevel)
{
_ = services
.AddGitHubActionsCore();
services.TryAddEnumerable(ServiceDescriptor.Singleton<ConsoleFormatter, CondensedConsoleFormatter>());
_ = services.AddLogging(x => x
Expand All @@ -27,9 +35,6 @@ public static ServiceProvider CreateServiceProvider(ref string[] args, Action<IS
.AddConsole(c => c.FormatterName = "condensed")
);

configure?.Invoke(services);

return services.BuildServiceProvider();
}

private static void ProcessCommandLineArguments(ref string[] args, ref LogLevel defaultLogLevel)
Expand Down
29 changes: 6 additions & 23 deletions src/Elastic.Markdown/Slices/HtmlWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,13 @@
// See the LICENSE file in the project root for more information
using System.IO.Abstractions;
using Elastic.Markdown.IO;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using RazorSlices;

namespace Elastic.Markdown.Slices;

public class HtmlWriter
public class HtmlWriter(DocumentationSet documentationSet, IFileSystem writeFileSystem)
{
private readonly IFileSystem _writeFileSystem;

public HtmlWriter(DocumentationSet documentationSet, IFileSystem writeFileSystem)
{
_writeFileSystem = writeFileSystem;
var services = new ServiceCollection();
_ = services.AddLogging();

ServiceProvider = services.BuildServiceProvider();
LoggerFactory = ServiceProvider.GetRequiredService<ILoggerFactory>();
DocumentationSet = documentationSet;
}

private DocumentationSet DocumentationSet { get; }
public ILoggerFactory LoggerFactory { get; }
public ServiceProvider ServiceProvider { get; }
private DocumentationSet DocumentationSet { get; } = documentationSet;

private async Task<string> RenderNavigation(MarkdownFile markdown, Cancel ctx = default)
{
Expand Down Expand Up @@ -79,7 +62,6 @@ public async Task WriteAsync(IFileInfo outputFile, MarkdownFile markdown, Cancel
if (outputFile.Directory is { Exists: false })
outputFile.Directory.Create();

var rendered = await RenderLayout(markdown, ctx);
string path;
if (outputFile.Name == "index.md")
path = Path.ChangeExtension(outputFile.FullName, ".html");
Expand All @@ -89,15 +71,16 @@ public async Task WriteAsync(IFileInfo outputFile, MarkdownFile markdown, Cancel
? null
: Path.Combine(outputFile.Directory.FullName, Path.GetFileNameWithoutExtension(outputFile.Name));

if (dir is not null && !_writeFileSystem.Directory.Exists(dir))
_ = _writeFileSystem.Directory.CreateDirectory(dir);
if (dir is not null && !writeFileSystem.Directory.Exists(dir))
_ = writeFileSystem.Directory.CreateDirectory(dir);

path = dir is null
? Path.GetFileNameWithoutExtension(outputFile.Name) + ".html"
: Path.Combine(dir, "index.html");
}

await _writeFileSystem.File.WriteAllTextAsync(path, rendered, ctx);
var rendered = await RenderLayout(markdown, ctx);
await writeFileSystem.File.WriteAllTextAsync(path, rendered, ctx);
}

}
8 changes: 2 additions & 6 deletions src/Elastic.Markdown/Slices/Layout/_TocTreeNav.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@
var f = file.File;
<li class="block ml-2 pl-2 border-l-1 border-l-gray-200 group/li">
<div class="flex">
<a
class="sidebar-link my-1 ml-5 group-[.current]/li:text-blue-elastic!"
id="page-@id"
href="@f.Url">
@f.NavigationTitle
</a>
<a class="sidebar-link my-1 ml-5 group-[.current]/li:text-blue-elastic!"
id="page-@id" href="@f.Url">@f.NavigationTitle</a>
</div>
</li>
}
Expand Down
7 changes: 3 additions & 4 deletions src/docs-builder/Http/DocumentationWebHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System.IO.Abstractions;
using Documentation.Builder.Diagnostics.LiveMode;
using Elastic.Documentation.Tooling;
using Elastic.Markdown;
using Elastic.Markdown.IO;
using Microsoft.AspNetCore.Builder;
Expand All @@ -28,14 +29,12 @@ public class DocumentationWebHost
public DocumentationWebHost(string? path, int port, ILoggerFactory logger, IFileSystem fileSystem)
{
var builder = WebApplication.CreateSlimBuilder();
DocumentationTooling.CreateServiceCollection(builder.Services, LogLevel.Warning);

_ = builder.Logging
.ClearProviders()
.SetMinimumLevel(LogLevel.Warning)
.AddFilter("Microsoft.AspNetCore.Hosting.Diagnostics", LogLevel.Error)
.AddFilter("Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware", LogLevel.Error)
.AddFilter("Microsoft.Hosting.Lifetime", LogLevel.Information)
.AddSimpleConsole(o => o.SingleLine = true);
.AddFilter("Microsoft.Hosting.Lifetime", LogLevel.Information);

_context = new BuildContext(fileSystem, fileSystem, path, null)
{
Expand Down