Merge branch 'netcore/dev' into netcore/feature/in-memory-runtime-minifier

# Conflicts:
#	src/Umbraco.Web.Common/DependencyInjection/UmbracoBuilderExtensions.cs
This commit is contained in:
Shannon
2021-03-16 17:49:05 +11:00
61 changed files with 1140 additions and 752 deletions

View File

@@ -12,7 +12,9 @@ using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Primitives;
using Serilog;
using Smidge;
using Smidge.Nuglify;
@@ -217,8 +219,9 @@ namespace Umbraco.Extensions
/// <summary>
/// Add runtime minifier support for Umbraco
/// </summary>
public static IUmbracoBuilder AddRuntimeMinifier(this IUmbracoBuilder builder)
public static IUmbracoBuilder AddRuntimeMinifier(this IUmbracoBuilder builder, IWebHostEnvironment webHostEnvironment)
{
var smidgePhysicalFileProvider = new SmidgePhysicalFileProvider(webHostEnvironment.ContentRootFileProvider, webHostEnvironment.WebRootFileProvider);
builder.Services.AddSmidge(builder.Config.GetSection(Constants.Configuration.ConfigRuntimeMinification));
builder.Services.AddSmidgeNuglify();
@@ -412,5 +415,29 @@ namespace Umbraco.Extensions
return new AspNetCoreHostingEnvironment(wrappedHostingSettings,wrappedWebRoutingSettings, webHostEnvironment);
}
/// <summary>
/// This file provider lets us serve physical files to Smidge for minification from both wwwroot and App_Plugins (which is outside wwwroot).
/// This file provider is NOT intended for use anywhere else, as it exposes files from the content root.
/// </summary>
private class SmidgePhysicalFileProvider : IFileProvider
{
private readonly IFileProvider _contentRootFileProvider;
private readonly IFileProvider _webRooFileProvider;
public SmidgePhysicalFileProvider(IFileProvider contentRootFileProvider, IFileProvider webRooFileProvider)
{
_contentRootFileProvider = contentRootFileProvider;
_webRooFileProvider = webRooFileProvider;
}
public IFileInfo GetFileInfo(string subpath) => subpath.InvariantStartsWith(Constants.SystemDirectories.AppPlugins)
? _contentRootFileProvider.GetFileInfo(subpath)
: _webRooFileProvider.GetFileInfo(subpath);
public IDirectoryContents GetDirectoryContents(string subpath) => throw new NotSupportedException();
public IChangeToken Watch(string filter) => throw new NotSupportedException();
}
}
}

View File

@@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core.Cache;
using Umbraco.Cms.Core.Configuration;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.DependencyInjection;
@@ -102,10 +103,14 @@ namespace Umbraco.Extensions
builder.AddNotificationHandler<ModelBindingError, ModelsBuilderNotificationHandler>();
builder.AddNotificationHandler<UmbracoApplicationStarting, LiveModelsProvider>();
builder.AddNotificationHandler<UmbracoRequestEnd, LiveModelsProvider>();
builder.AddNotificationHandler<UmbracoApplicationStarting, OutOfDateModelsStatus>();
builder.AddNotificationHandler<ContentTypeCacheRefresherNotification, LiveModelsProvider>();
builder.AddNotificationHandler<DataTypeCacheRefresherNotification, LiveModelsProvider>();
builder.Services.AddSingleton<ModelsGenerator>();
builder.Services.AddSingleton<LiveModelsProvider>();
builder.Services.AddSingleton<OutOfDateModelsStatus>();
builder.AddNotificationHandler<ContentTypeCacheRefresherNotification, OutOfDateModelsStatus>();
builder.AddNotificationHandler<DataTypeCacheRefresherNotification, OutOfDateModelsStatus>();
builder.Services.AddSingleton<ModelsGenerationError>();
builder.Services.AddSingleton<PureLiveModelFactory>();

View File

@@ -118,31 +118,29 @@ namespace Umbraco.Cms.Web.Common.Views
// ASP.NET default value is text/html
if (Context.Response.ContentType.InvariantContains("text/html"))
{
if (UmbracoContext.IsDebug || UmbracoContext.InPreviewMode)
if ((UmbracoContext.IsDebug || UmbracoContext.InPreviewMode)
&& tagHelperOutput.TagName != null
&& tagHelperOutput.TagName.Equals("body", StringComparison.InvariantCultureIgnoreCase))
{
string markupToInject;
if (tagHelperOutput.TagName.Equals("body", StringComparison.InvariantCultureIgnoreCase))
if (UmbracoContext.InPreviewMode)
{
string markupToInject;
if (UmbracoContext.InPreviewMode)
{
// creating previewBadge markup
markupToInject =
string.Format(
ContentSettings.PreviewBadge,
IOHelper.ResolveUrl(GlobalSettings.UmbracoPath),
Context.Request.GetEncodedUrl(),
UmbracoContext.PublishedRequest.PublishedContent.Id);
}
else
{
// creating mini-profiler markup
markupToInject = ProfilerHtml.Render();
}
tagHelperOutput.Content.AppendHtml(markupToInject);
// creating previewBadge markup
markupToInject =
string.Format(
ContentSettings.PreviewBadge,
IOHelper.ResolveUrl(GlobalSettings.UmbracoPath),
Context.Request.GetEncodedUrl(),
UmbracoContext.PublishedRequest.PublishedContent.Id);
}
else
{
// creating mini-profiler markup
markupToInject = ProfilerHtml.Render();
}
tagHelperOutput.Content.AppendHtml(markupToInject);
}
}
}