|
|
|
@ -4,27 +4,27 @@ using System.Linq; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Microsoft.AspNetCore.Hosting; |
|
|
|
using Microsoft.AspNetCore.Mvc.Rendering; |
|
|
|
using Microsoft.AspNetCore.Mvc.Routing; |
|
|
|
using Microsoft.AspNetCore.Mvc.ViewFeatures; |
|
|
|
using Microsoft.AspNetCore.Razor.TagHelpers; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.Hosting; |
|
|
|
using Microsoft.Extensions.Options; |
|
|
|
using Volo.Abp.AspNetCore.VirtualFileSystem; |
|
|
|
|
|
|
|
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers |
|
|
|
{ |
|
|
|
public class AbpTagHelperStyleService : AbpTagHelperResourceService |
|
|
|
{ |
|
|
|
protected AbpTagHelperScriptStyleLoadingOptions LoadingOptions { get; } |
|
|
|
|
|
|
|
public AbpTagHelperStyleService( |
|
|
|
IBundleManager bundleManager, |
|
|
|
IOptions<AbpBundlingOptions> options, |
|
|
|
IWebHostEnvironment hostingEnvironment |
|
|
|
) : base( |
|
|
|
IWebHostEnvironment hostingEnvironment, |
|
|
|
IOptions<AbpTagHelperScriptStyleLoadingOptions> loadingOptions) : base( |
|
|
|
bundleManager, |
|
|
|
options, |
|
|
|
hostingEnvironment) |
|
|
|
{ |
|
|
|
LoadingOptions = loadingOptions.Value; |
|
|
|
} |
|
|
|
|
|
|
|
protected override void CreateBundle(string bundleName, List<BundleTagHelperItem> bundleItems) |
|
|
|
@ -41,9 +41,23 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers |
|
|
|
return await BundleManager.GetStyleBundleFilesAsync(bundleName); |
|
|
|
} |
|
|
|
|
|
|
|
protected override void AddHtmlTag(ViewContext viewContext, TagHelperContext context, TagHelperOutput output, string file) |
|
|
|
protected override void AddHtmlTag(ViewContext viewContext, TagHelper tagHelper, TagHelperContext context, TagHelperOutput output, string file) |
|
|
|
{ |
|
|
|
output.Content.AppendHtml($"<link rel=\"stylesheet\" href=\"{viewContext.GetUrlHelper().Content(file.EnsureStartsWith('~'))}\" />{Environment.NewLine}"); |
|
|
|
var preload = tagHelper switch |
|
|
|
{ |
|
|
|
AbpStyleTagHelper styleTagHelper => styleTagHelper.Preload, |
|
|
|
AbpStyleBundleTagHelper styleBundleTagHelper => styleBundleTagHelper.Preload, |
|
|
|
_ => false |
|
|
|
}; |
|
|
|
|
|
|
|
if (preload || LoadingOptions.GlobalPreloadStyle || LoadingOptions.PreloadStyles.Any(x => file.StartsWith(x, StringComparison.OrdinalIgnoreCase))) |
|
|
|
{ |
|
|
|
output.Content.AppendHtml($"<link rel=\"preload\" href=\"{viewContext.GetUrlHelper().Content(file.EnsureStartsWith('~'))}\" as=\"style\" onload=\"this.rel='stylesheet'\" />{Environment.NewLine}"); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
output.Content.AppendHtml($"<link rel=\"stylesheet\" href=\"{viewContext.GetUrlHelper().Content(file.EnsureStartsWith('~'))}\" />{Environment.NewLine}"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|