From 9db31e75b4f890f1141fc7fb1caf536a3d693aa0 Mon Sep 17 00:00:00 2001 From: maliming Date: Thu, 9 Nov 2023 17:13:52 +0800 Subject: [PATCH] Rename `CDN` to `External`. --- docs/en/UI/AspNetCore/Bundling-Minification.md | 16 ++++++++-------- .../UI/AspNetCore/Bundling-Minification.md | 17 ++++++++--------- .../Bundling/BundleConfigurationExtensions.cs | 4 ++-- .../BundleContributorCollectionExtensions.cs | 2 +- .../AspNetCore/Mvc/UI/Bundling/BundleFile.cs | 15 ++++++++++++--- .../AspNetCore/Mvc/UI/Bundling/BundleManager.cs | 2 +- .../TagHelpers/AbpBundleItemTagHelper.cs | 5 +---- .../TagHelpers/AbpTagHelperResourceService.cs | 2 +- .../TagHelpers/AbpTagHelperScriptService.cs | 2 +- .../TagHelpers/AbpTagHelperStyleService.cs | 2 +- 10 files changed, 36 insertions(+), 31 deletions(-) diff --git a/docs/en/UI/AspNetCore/Bundling-Minification.md b/docs/en/UI/AspNetCore/Bundling-Minification.md index 650d3e3e77..6164d00c7d 100644 --- a/docs/en/UI/AspNetCore/Bundling-Minification.md +++ b/docs/en/UI/AspNetCore/Bundling-Minification.md @@ -382,11 +382,11 @@ Configure(options => ```` -### CDN Support +### External/CDN file Support -You can configure `AbpBundlingOptions` or use `is-cdn` on `script/style` taghelper to load all or a single js/css file from CDN. +The bundling system automatically recognizes the external/CDN files and adds them to the page without any change. -#### Add CDN files in `AbpBundlingOptions` +#### Using External/CDN files in `AbpBundlingOptions` ````csharp Configure(options => @@ -397,7 +397,7 @@ Configure(options => configuration .AddFiles("/styles/my-style1.css") .AddFiles("/styles/my-style2.css") - .AddCdnFiles("https://cdn.abp.io/bootstrap.css") + .AddFiles("https://cdn.abp.io/bootstrap.css") .AddFiles("/styles/my-style3.css") .AddFiles("/styles/my-style4.css"); }); @@ -408,7 +408,7 @@ Configure(options => configuration .AddFiles("/scripts/my-script1.js") .AddFiles("/scripts/my-script2.js") - .AddCdnFiles("https://cdn.abp.io/bootstrap.js") + .AddFiles("https://cdn.abp.io/bootstrap.js") .AddFiles("/scripts/my-script3.js") .AddFiles("/scripts/my-script4.js"); }); @@ -427,13 +427,13 @@ Configure(options => ```` -#### Add CDN files in Tag Helpers. +#### Using External/CDN files in Tag Helpers. ````html - + @@ -441,7 +441,7 @@ Configure(options => - + diff --git a/docs/zh-Hans/UI/AspNetCore/Bundling-Minification.md b/docs/zh-Hans/UI/AspNetCore/Bundling-Minification.md index fab0893a76..72bee2eedb 100644 --- a/docs/zh-Hans/UI/AspNetCore/Bundling-Minification.md +++ b/docs/zh-Hans/UI/AspNetCore/Bundling-Minification.md @@ -353,11 +353,11 @@ services.Configure(options => }); ```` -### CDN 支持 +### 外部/CDN文件支持 -你可以配置`AbpBundlingOptions`或在`script/style` taghelper上使用`is-cdn`来从CDN加载js/css. +捆绑系统会自动识别外部/CDN文件,并将其添加到页面中,无需进行任何更改。 -#### 在`AbpBundlingOptions`中添加CDN文件 +#### 在`AbpBundlingOptions`中添加外部/CDN文件 ````csharp Configure(options => @@ -368,7 +368,7 @@ Configure(options => configuration .AddFiles("/styles/my-style1.css") .AddFiles("/styles/my-style2.css") - .AddCdnFiles("https://cdn.abp.io/bootstrap.css") + .AddFiles("https://cdn.abp.io/bootstrap.css") .AddFiles("/styles/my-style3.css") .AddFiles("/styles/my-style4.css"); }); @@ -379,7 +379,7 @@ Configure(options => configuration .AddFiles("/scripts/my-script1.js") .AddFiles("/scripts/my-script2.js") - .AddCdnFiles("https://cdn.abp.io/bootstrap.js") + .AddFiles("https://cdn.abp.io/bootstrap.js") .AddFiles("/scripts/my-script3.js") .AddFiles("/scripts/my-script4.js"); }); @@ -398,13 +398,13 @@ Configure(options => ```` -#### 在TagHelpers中添加CDN文件 +#### 在TagHelpers中添加外部/CDN文件 ````html - + @@ -412,7 +412,7 @@ Configure(options => - + @@ -430,7 +430,6 @@ Configure(options => ```` - ### 主题 主题使用标准包贡献者将库资源添加到页面布局. 主题还可以定义一些标准/全局包, 因此任何模块都可以为这些标准/全局包做出贡献. 有关更多信息, 请参阅[主题文档](Theming.md). diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationExtensions.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationExtensions.cs index 8dd51dc5a3..62f7950c5a 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationExtensions.cs @@ -17,9 +17,9 @@ public static class BundleConfigurationExtensions return bundleConfiguration; } - public static BundleConfiguration AddCdnFiles(this BundleConfiguration bundleConfiguration, params string[] files) + public static BundleConfiguration AddExternalFiles(this BundleConfiguration bundleConfiguration, params string[] files) { - bundleConfiguration.Contributors.AddCdnFiles(files.Select(x => new BundleFile(x, true)).ToArray()); + bundleConfiguration.Contributors.AddExternalFiles(files.Select(x => new BundleFile(x, true)).ToArray()); return bundleConfiguration; } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleContributorCollectionExtensions.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleContributorCollectionExtensions.cs index 22bfe2947c..addbe7e2cd 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleContributorCollectionExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleContributorCollectionExtensions.cs @@ -12,7 +12,7 @@ public static class BundleContributorCollectionExtensions contributors.Add(new BundleFileContributor(files)); } - public static void AddCdnFiles(this BundleContributorCollection contributors, params BundleFile[] files) + public static void AddExternalFiles(this BundleContributorCollection contributors, params BundleFile[] files) { contributors.Add(new BundleFileContributor(files)); } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleFile.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleFile.cs index 091a4b3823..fbd6c3eaa1 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleFile.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleFile.cs @@ -1,15 +1,24 @@ +using System; + namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling; public class BundleFile { public string FileName { get; set; } - public bool IsCdn { get; set; } + public bool IsExternalFile { get; set; } + + public BundleFile(string fileName) + { + FileName = fileName; + IsExternalFile = fileName.StartsWith("http://", StringComparison.OrdinalIgnoreCase) || + fileName.StartsWith("https://", StringComparison.OrdinalIgnoreCase); + } - public BundleFile(string fileName, bool isCdn = false) + public BundleFile(string fileName, bool isExternalFile) { FileName = fileName; - IsCdn = isCdn; + IsExternalFile = isExternalFile; } /// diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleManager.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleManager.cs index 9e5ca4bdef..20c33e86e5 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleManager.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleManager.cs @@ -81,7 +81,7 @@ public class BundleManager : IBundleManager, ITransientDependency var localBundleFiles = new List(); foreach (var bundleFile in bundleFiles) { - if (!bundleFile.IsCdn) + if (!bundleFile.IsExternalFile) { localBundleFiles.Add(bundleFile.FileName); } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpBundleItemTagHelper.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpBundleItemTagHelper.cs index 81c06df7c3..03ed327dc0 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpBundleItemTagHelper.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpBundleItemTagHelper.cs @@ -18,9 +18,6 @@ public abstract class AbpBundleItemTagHelper : Ab /// public Type? Type { get; set; } - [HtmlAttributeName("is-cdn")] - public bool IsCdn { get; set; } - protected AbpBundleItemTagHelper(TTagHelperService service) : base(service) { @@ -53,7 +50,7 @@ public abstract class AbpBundleItemTagHelper : Ab if (Src != null) { - return new BundleTagHelperFileItem(new BundleFile(Src, IsCdn)); + return new BundleTagHelperFileItem(new BundleFile(Src)); } throw new AbpException("abp-script tag helper requires to set either src or type!"); diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperResourceService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperResourceService.cs index 5a19dee915..9be91c535f 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperResourceService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperResourceService.cs @@ -65,7 +65,7 @@ public abstract class AbpTagHelperResourceService : ITransientDependency foreach (var bundleFile in bundleFiles) { - if (bundleFile.IsCdn) + if (bundleFile.IsExternalFile) { AddHtmlTag(viewContext, tagHelper, context, output, bundleFile, null); } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperScriptService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperScriptService.cs index ea0f11b777..c8486ebadd 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperScriptService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperScriptService.cs @@ -53,7 +53,7 @@ public class AbpTagHelperScriptService : AbpTagHelperResourceService var nonceText = (viewContext.HttpContext.Items.TryGetValue(AbpAspNetCoreConsts.ScriptNonceKey, out var nonce) && nonce is string nonceString && !string.IsNullOrEmpty(nonceString)) ? $"nonce=\"{nonceString}\" " : string.Empty; - var src = file.IsCdn ? file.FileName : viewContext.GetUrlHelper().Content((file.FileName + "?_v=" + fileInfo!.LastModified.UtcTicks).EnsureStartsWith('~')); + var src = file.IsExternalFile ? file.FileName : viewContext.GetUrlHelper().Content((file.FileName + "?_v=" + fileInfo!.LastModified.UtcTicks).EnsureStartsWith('~')); output.Content.AppendHtml($"{Environment.NewLine}"); } } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperStyleService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperStyleService.cs index 63f2e2304d..bcfd7d95e2 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperStyleService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperStyleService.cs @@ -51,7 +51,7 @@ public class AbpTagHelperStyleService : AbpTagHelperResourceService _ => false }; - var href = file.IsCdn ? file.FileName : viewContext.GetUrlHelper().Content((file.FileName + "?_v=" + fileInfo!.LastModified.UtcTicks).EnsureStartsWith('~')); + var href = file.IsExternalFile ? file.FileName : viewContext.GetUrlHelper().Content((file.FileName + "?_v=" + fileInfo!.LastModified.UtcTicks).EnsureStartsWith('~')); if (preload || Options.PreloadStylesByDefault || Options.PreloadStyles.Any(x => file.FileName.StartsWith(x, StringComparison.OrdinalIgnoreCase))) { output.Content.AppendHtml(SecurityHeadersOptions.UseContentSecurityPolicyScriptNonce