Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Johnson committed Nov 28, 2021
2 parents 4e9e194 + f370c08 commit 10b9585
Show file tree
Hide file tree
Showing 75 changed files with 73 additions and 105 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ $ dotnet tool install --global Umbraco.Docs.Preview.App

```bash
$ umbracodocs # run from UmbracoDocs repo root
$ umbracodocs -h # view help.
```

And you're ready to view the docs by default at http://localhost:5000.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,61 +1,24 @@
using System.IO;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Logging;
using Umbraco.Docs.Preview.App.MiscellaneousOurStuff;
using Umbraco.Docs.Preview.App.Models;
using Microsoft.Extensions.Options;
using Umbraco.Docs.Preview.App.Options;

namespace Umbraco.Docs.Preview.App.Extensions
{
public static class UmbracoDocsApplicationBuilderExtensions
{
public static IApplicationBuilder UseUmbracoDocsImageFileProviders(this IApplicationBuilder app)
{
var serviceProvider = app.ApplicationServices;
var settings = app.ApplicationServices.GetRequiredService<IOptions<UmbracoDocsOptions>>();

var tree = serviceProvider.GetRequiredService<DocumentationUpdater>().BuildSitemap();

var log = serviceProvider
.GetRequiredService<ILoggerFactory>()
.CreateLogger(typeof(UmbracoDocsApplicationBuilderExtensions));

var total = AddImageFileProviders(tree, app, log);
log.LogInformation("Found {count} image directories for UmbracoDocs", total);

log.LogWarning("Images from new documentation sub directories will not be served without a restart");

return app;
}

private static int AddImageFileProviders(UmbracoDocsTreeNode node, IApplicationBuilder app, ILogger log)
{
var counter = 0;
var path = Path.Combine(node.PhysicalPath, "images");

var requestPath = $"/documentation/{node.Path}/images"
.Replace("//", "/"); // Hack for root UmbracoDocs folder

if (Directory.Exists(path))
app.UseStaticFiles(new StaticFileOptions
{
log.LogDebug("Adding file provider for {path}", path);

app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(path),
RequestPath = requestPath
});

++counter;
}
FileProvider = new PhysicalFileProvider(settings.Value.UmbracoDocsRootFolder),
RequestPath = "/documentation"
});

// Could add these to a composite?
foreach (var child in node.Directories)
{
counter += AddImageFileProviders(child, app, log);
}

return counter;
return app;
}
}
}
65 changes: 44 additions & 21 deletions src/Umbraco.Docs.Preview.App/Program.cs
Original file line number Diff line number Diff line change
@@ -1,48 +1,71 @@
using System;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.IO;
using System.Reflection;
using Lamar.Microsoft.DependencyInjection;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Umbraco.Docs.Preview.App.Options;

namespace Umbraco.Docs.Preview.App
{
public class Program
{
public static int Main(string[] args)
{
var directory = Directory.GetCurrentDirectory();
if (!File.Exists(Path.Combine(directory, "index.md")))
var rootCommand = new RootCommand
{
Console.Error.WriteLine("Fatal Error: current directory doesn't appear to be the UmbracoDocs repo.");
return -1;
}

CreateHostBuilder(args)
.Build()
.Run();
new Argument
{
Name = "path",
Arity = new ArgumentArity(0, 1),
Description = "Path to UmbracoDocs repository."
}
};
rootCommand.Name = "umbracodocs";
rootCommand.Description = "Run UmbracoDocs preview server";
rootCommand.Handler = CommandHandler.Create<string>(RunServer);

return 0;
return rootCommand.Invoke(args);
}

public static IHostBuilder CreateHostBuilder(string[] args)
private static int RunServer(string path = null)
{
// dotnet tools configure cwd as you would expect, but Host.CreateDefaultBuilder isn't expecting that
// to be miles away from appsettings.json and wwwroot etc.
// So more config, less convention for ContentRoot
var applicationFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
path ??= Directory.GetCurrentDirectory();

var docsAbsolutePath = Path.GetFullPath(path);


if (!File.Exists(Path.Combine(docsAbsolutePath!, "index.md")))
{
Console.Error.WriteLine("Fatal Error: current directory doesn't appear to be the UmbracoDocs repo.");
return -1;
}

return Host.CreateDefaultBuilder(args)
.UseContentRoot(applicationFolder)
Host.CreateDefaultBuilder(new[] { path })
#if !DEBUG
// dotnet tools configures cwd as you would expect, but Host.CreateDefaultBuilder isn't expecting that
// to be miles away from appsettings.json and wwwroot etc.
// So more prefer configuration over convention for ContentRoot (unless debugging).
.UseContentRoot(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location))
#endif
.UseLamar()
.UseConsoleLifetime()
.ConfigureWebHostDefaults(webBuilder =>
{
#if !DEBUG
webBuilder.UseEnvironment("Production");
#endif
webBuilder.ConfigureServices(services =>
{
services.Configure<UmbracoDocsOptions>(cfg => cfg.UmbracoDocsRootFolder = docsAbsolutePath);
});
webBuilder.UseStartup<Startup>();
});

})
.Build()
.Run();

return 0;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"profiles": {
"Development": {
"workingDirectory": "../../../UmbracoDocs/",
"commandLineArgs": "../../../UmbracoDocs/",
"commandName": "Project",
"dotnetRunMessages": "true",
"launchBrowser": true,
Expand Down
3 changes: 0 additions & 3 deletions src/Umbraco.Docs.Preview.App/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.IO;
using Castle.DynamicProxy;
using Lamar;
using MediatR;
Expand All @@ -11,7 +10,6 @@
using Umbraco.Docs.Preview.App.HostedServices;
using Umbraco.Docs.Preview.App.Interceptors.Caching;
using Umbraco.Docs.Preview.App.MiscellaneousOurStuff;
using Umbraco.Docs.Preview.App.Options;
using Umbraco.Docs.Preview.App.Services;

namespace Umbraco.Docs.Preview.App
Expand All @@ -26,7 +24,6 @@ public void ConfigureContainer(ServiceRegistry services)

services.AddSingleton<IMarkdownService, MarkdownService>();
services.AddSingleton<DocumentationUpdater>();
services.Configure<UmbracoDocsOptions>(cfg => cfg.UmbracoDocsRootFolder = Directory.GetCurrentDirectory());

services.For<IDocumentService>()
.Add<DocumentService>()
Expand Down
5 changes: 3 additions & 2 deletions src/Umbraco.Docs.Preview.App/Umbraco.Docs.Preview.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<PropertyGroup>
<Version>0.1.1</Version>
<Version>0.1.2</Version>
<Company>Umbraco HQ</Company>
<Description>Enables local preview of UmbracoDocs.</Description>
<PackageTags>umbraco</PackageTags>
Expand All @@ -26,11 +26,12 @@
<PackageReference Include="Lamar.Microsoft.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Markdig" Version="0.26.0" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="9.0.0" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.21308.1" />
<!--<PackageReference Include="Markdig.SyntaxHighlighting" Version="1.1.7" />--> <!--Windows only-->
</ItemGroup>

<ItemGroup>
<None Include="logo-small.png" Pack="true" PackagePath="\"/>
<None Include="logo-small.png" Pack="true" PackagePath="\" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@using Microsoft.AspNetCore.Http
@using Umbraco.Docs.Preview.App.Extensions
@model Umbraco.Docs.Preview.App.Models.DocumentationViewModel

@inject IHttpContextAccessor _contextAccessor;
Expand All @@ -7,12 +8,17 @@
public string IsActive(string path, string classname = "active")
{
var requestPath = $"{_contextAccessor?.HttpContext?.Request.Path}";
return requestPath.ToLower().StartsWith(path.ToLower()) ? classname : string.Empty;
return requestPath.ToLower().StartsWith(path.RemoveEmptyFolderParts().ToLower()) ? classname : string.Empty;
}

public string NavUrl(string path)
{
return $"{path}/".RemoveEmptyFolderParts();
}
}

@{
const string root = "/documentation";
const string root = "/documentation/";
}

<nav>
Expand All @@ -28,22 +34,23 @@
&& item.Name != "Cheatsheets")
{
<li class=" @IsActive(root+item.Path, "active open")">
<a href="@(root + item.Path)/"><h3>@item.Name</h3></a>
<a href="@NavUrl(root + item.Path)"><h3>@item.Name</h3></a>

@if (item.HasChildren)
{
<ul class="level-2 @IsActive(root + item.Path, "open")">
@foreach (var itemChild in item.Directories)
{
<li class=" @IsActive(root + itemChild.Path, "active open")">
<a href="@(root + itemChild.Path)/"><h4>@itemChild.Name</h4></a>
<a href="@NavUrl(root + itemChild.Path)"><h4>@itemChild.Name</h4></a>

@if (itemChild.HasChildren)
{
<ul class="level-3 @IsActive(root + item.Path, "open")">
@foreach (var itemGrandChild in itemChild.Directories)
{
<li class=" @IsActive(root + itemGrandChild.Path, "active")"><a href="@(root + itemGrandChild.Path)/"><h5>@itemGrandChild.Name</h5></a></li>
<li class=" @IsActive(root + itemGrandChild.Path, "active")">
<a href="@NavUrl(root + itemGrandChild.Path)"><h5>@itemGrandChild.Name</h5></a></li>
}
</ul>
}
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Loading

0 comments on commit 10b9585

Please sign in to comment.