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 27, 2021
2 parents a2c3c5f + 0c9fe9d commit 4e9e194
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 102 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ This project can be found on nuget at https://www.nuget.org/packages/Umbraco.Doc
You can run the following to install as a global tool.

```bash
$ dotnet tool install --global Umbraco.Docs.Preview.App --version 0.1.0-beta
$ dotnet tool install --global Umbraco.Docs.Preview.App
```

## Running the project
Expand All @@ -37,14 +37,14 @@ This could be useful for testing contributions to UmbracoDocs or just to facilit
connection.


## install local build
## Install local build

```bash
$ dotnet pack -o dist
$ dotnet tool install -g --add-source ./dist --version 0.1.0-beta Umbraco.Docs.Preview.App
$ dotnet tool install -g --add-source ./dist Umbraco.Docs.Preview.App
```

## I don't want this anymore
## Uninstall
```bash
$ dotnet tool uninstall -g umbraco.docs.preview.app
```
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ public static IApplicationBuilder UseUmbracoDocsImageFileProviders(this IApplica
.GetRequiredService<ILoggerFactory>()
.CreateLogger(typeof(UmbracoDocsApplicationBuilderExtensions));

log.LogWarning("Images from new documentation sub directories will not be served without a restart");
var total = AddImageFileProviders(tree, app, log);
log.LogInformation("Found {count} image directories for UmbracoDocs", total);

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

return app;
}

private static void AddImageFileProviders(UmbracoDocsTreeNode node, IApplicationBuilder app, ILogger log)
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"
Expand All @@ -43,22 +45,17 @@ private static void AddImageFileProviders(UmbracoDocsTreeNode node, IApplication
FileProvider = new PhysicalFileProvider(path),
RequestPath = requestPath
});

++counter;
}

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

public static IApplicationBuilder UseOurUmbracoEmbeddedResources(this IApplicationBuilder app)
{
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new ManifestEmbeddedFileProvider(typeof(Program).Assembly, "wwwroot"),
RequestPath = ""
});
return app;
return counter;
}
}
}

This file was deleted.

49 changes: 29 additions & 20 deletions src/Umbraco.Docs.Preview.App/Program.cs
Original file line number Diff line number Diff line change
@@ -1,39 +1,48 @@
using System;
using System.IO;
using System.Reflection;
using Lamar.Microsoft.DependencyInjection;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

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

CreateHostBuilder(args)
.Build()
.Run();

return 0;
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
public static IHostBuilder CreateHostBuilder(string[] args)
{
// 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);

return Host.CreateDefaultBuilder(args)
.UseContentRoot(applicationFolder)
.UseLamar()
.UseConsoleLifetime()
.ConfigureLogging(cfg =>
{
cfg.AddConsole();
cfg.AddDebug();
cfg.AddFilter((_, log, level) =>
{
// TODO: move to config somewhere.
if (log.StartsWith("Umbraco") && level >= LogLevel.Debug)
return true;
if (log.StartsWith("Microsoft.Hosting.Lifetime") && level >= LogLevel.Debug)
return true;
return false;
});
cfg.SetMinimumLevel(LogLevel.Warning);
})
.ConfigureWebHostDefaults(webBuilder =>
{
#if !DEBUG
webBuilder.UseEnvironment("Production");
#endif
webBuilder.UseStartup<Startup>();
});
}
}
}
1 change: 1 addition & 0 deletions src/Umbraco.Docs.Preview.App/Services/IDocumentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Umbraco.Docs.Preview.App.Services
public interface IDocumentService
{
bool TryFindMarkdownFile(string slug, out DocumentVersion version);

IEnumerable<DocumentVersion> GetAlternates(DocumentVersion version);

[CacheIndefinitely(CacheKey = nameof(GetDocsTree))]
Expand Down
23 changes: 4 additions & 19 deletions src/Umbraco.Docs.Preview.App/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using Castle.DynamicProxy;
using Lamar;
using MediatR;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Logging;
using Umbraco.Docs.Preview.App.Extensions;
using Umbraco.Docs.Preview.App.HostedServices;
using Umbraco.Docs.Preview.App.Interceptors.Caching;
Expand All @@ -27,7 +26,7 @@ public void ConfigureContainer(ServiceRegistry services)

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

services.For<IDocumentService>()
.Add<DocumentService>()
Expand All @@ -47,21 +46,8 @@ public void ConfigureContainer(ServiceRegistry services)
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILogger<Startup> log)
{
var opts = app.ApplicationServices.GetRequiredService<IOptions<UmbracoDocsOptions>>();
if (opts.Value.UmbracoDocsRootFolder == null)
{
Task.Run(() =>
{
// TODO: Find better graceful shutdown.
Thread.Sleep(1000);
app.ApplicationServices.GetRequiredService<IHostApplicationLifetime>().StopApplication();
});

return;
}

if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
Expand All @@ -74,7 +60,6 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseStatusCodePages();

app.UseUmbracoDocsImageFileProviders();
app.UseOurUmbracoEmbeddedResources();

app.UseStaticFiles();

Expand Down
15 changes: 8 additions & 7 deletions src/Umbraco.Docs.Preview.App/Umbraco.Docs.Preview.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,32 @@
</PropertyGroup>

<PropertyGroup>
<Version>0.1.0-beta</Version>
<Version>0.1.1</Version>
<Company>Umbraco HQ</Company>
<Description>Enables local preview of UmbracoDocs.</Description>
<PackageTags>umbraco</PackageTags>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageIcon>logo-small.png</PackageIcon>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/umbraco/UmbracoDocs.Preview/</RepositoryUrl>
</PropertyGroup>

<PropertyGroup>
<IsPackable>true</IsPackable>
<PackAsTool>true</PackAsTool>
<ToolCommandName>umbracodocs</ToolCommandName>
</PropertyGroup>

<PropertyGroup>
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Castle.Core" Version="4.4.1" />
<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="Microsoft.Extensions.FileProviders.Embedded" Version="3.1.0" />
<!--<PackageReference Include="Markdig.SyntaxHighlighting" Version="1.1.7" />--> <!--Windows only-->
</ItemGroup>

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

</Project>
2 changes: 1 addition & 1 deletion src/Umbraco.Docs.Preview.App/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<div class="container">
<div class="row">
<div class="col-md-3">
<a class="logo" href="/">UmbracoDocs Preview</a>
<a class="logo" href="/documentation/">UmbracoDocs Preview</a>
</div>
<div id="toggle" class="menu-toggle">
<a href="#" class="toggle cross"><span></span></a>
Expand Down
9 changes: 9 additions & 0 deletions src/Umbraco.Docs.Preview.App/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Warning",
"Microsoft.Hosting.Lifetime": "Information",
"Umbraco.Docs": "Debug"
}
}
}
9 changes: 9 additions & 0 deletions src/Umbraco.Docs.Preview.App/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Critical",
"Microsoft.Hosting.Lifetime": "Information",
"Umbraco.Docs": "Information"
}
}
}
Binary file added src/Umbraco.Docs.Preview.App/logo-small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4e9e194

Please sign in to comment.