Skip to content

Commit 6056a9b

Browse files
authored
doc(StaticAsset): use WebsiteOption AssetRootPath parameter (#4775)
* refactor: 精简代码 * refactor: 更新脚本路径 * doc: 移除不使用的脚本 * refactor: 使用 WebSiteOption 读取脚本资源根路径 * refactor: 更新瀑布流资源路径 * refactor: 更新模板页加载脚本路径 * refactor: 更新图床路径 * refactor: 统一使用资源文件变量 * refactor: 更正脚本资源路径问题 * refactor: 更新头像路径 * refactor: 更新流程图资源路径 * refactor: 重构 Pre 组件内部资源文件路径 * refactor: 精简代码逻辑 * refactor: 增加第三方图标库样式 * refactor: 更新图标独立加载样式 * refactor: 更新鼠标跟随示例样式 * doc: 更新 Live2D 组件资源路径 * refactor: 重构静态资源路径 * refactor: 重构广告资源路径 * refactor: 重构资源路径 * refactor: 更新根目录变量 * chore: 更新忽略文件 * test: 更新单元测试 * Revert "chore: 更新忽略文件" This reverts commit 139cb79. * doc: 统一变量名称 * doc: 统一变量名称
1 parent b9869e9 commit 6056a9b

File tree

99 files changed

+488
-449
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+488
-449
lines changed

src/BootstrapBlazor.Server/Components/App.razor

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@inject IWebHostEnvironment Env
22
@inject IStringLocalizer<BaseLayout> Localizer
3+
@inject IOptions<WebsiteOptions> WebsiteOption
34

45
<!DOCTYPE html>
56
<html lang="en" data-bs-theme='light'>
@@ -18,23 +19,13 @@
1819
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
1920
<link rel="apple-touch-icon" href="favicon.png">
2021

21-
@if (Env.IsSupportAssets())
22-
{
23-
@this.RenderAssets()
24-
}
25-
else
26-
{
27-
<link rel="stylesheet" href="_content/BootstrapBlazor.AntDesignIcon/BootstrapBlazor.AntDesignIcon.bundle.scp.css" />
28-
<link rel="stylesheet" href="_content/BootstrapBlazor.BootstrapIcon/css/bootstrap.min.css" />
29-
<link rel="stylesheet" href="_content/BootstrapBlazor.ElementIcon/BootstrapBlazor.ElementIcon.bundle.scp.css" />
30-
<link rel="stylesheet" href="_content/BootstrapBlazor.FontAwesome/css/font-awesome.min.css" />
31-
<link rel="stylesheet" href="_content/BootstrapBlazor.MaterialDesign/css/md.min.css" />
32-
<link rel="stylesheet" href="_content/BootstrapBlazor.IconPark/BootstrapBlazor.IconPark.bundle.scp.css" />
33-
<link rel="stylesheet" href="_content/BootstrapBlazor/css/bootstrap.blazor.bundle.min.css" />
34-
<link rel="stylesheet" href="_content/BootstrapBlazor/css/motronic.min.css" />
35-
<link rel="stylesheet" href="_content/BootstrapBlazor.Shared/BootstrapBlazor.Shared.bundle.scp.css" />
36-
<link rel="stylesheet" href="_content/BootstrapBlazor.Shared/css/site.css" />
37-
}
22+
<link rel="stylesheet" href="@Assets["_content/BootstrapBlazor.FontAwesome/css/font-awesome.min.css"]" />
23+
<link rel="stylesheet" href="@Assets["_content/BootstrapBlazor.MaterialDesign/css/md.min.css"]" />
24+
<link rel="stylesheet" href="@Assets["_content/BootstrapBlazor/css/bootstrap.blazor.bundle.min.css"]" />
25+
<link rel="stylesheet" href="@Assets["_content/BootstrapBlazor/css/motronic.min.css"]" />
26+
<link rel="stylesheet" href="@Assets["_content/BootstrapBlazor.Shared/BootstrapBlazor.Shared.bundle.scp.css"]" />
27+
<link rel="stylesheet" href="@Assets["_content/BootstrapBlazor.Shared/css/site.css"]" />
28+
3829
<HeadOutlet @rendermode="new InteractiveServerRenderMode(false)" />
3930
</head>
4031

@@ -53,7 +44,7 @@
5344
@if (Env.IsProduction())
5445
{
5546
<script type="text/javascript" src="https://cdn.wwads.cn/js/makemoney.js"></script>
56-
<script type="text/javascript" src="./_content/BootstrapBlazor.Shared/lib/wwads/wwads.js"></script>
47+
<script type="text/javascript" src="@WebsiteOption.Value.GetAssetUrl("lib/wwads/wwads.js")"></script>
5748
<script>
5849
var _hmt = _hmt || [];
5950
(function () {

src/BootstrapBlazor.Server/Controllers/WaterfallController.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
55

66
using Microsoft.AspNetCore.Mvc;
7+
using Microsoft.Extensions.Options;
78

89
namespace BootstrapBlazor.Server.Controllers;
910

@@ -15,19 +16,19 @@ public class WaterfallController : Controller
1516
/// <summary>
1617
/// 获得图片方法
1718
/// </summary>
18-
/// <param name="env"></param>
19+
/// <param name="options"></param>
1920
/// <param name="id"></param>
2021
/// <returns></returns>
21-
public async Task<IActionResult> Index([FromServices] IWebHostEnvironment env, [FromQuery] string? id)
22+
public async Task<IActionResult> Index([FromServices] IOptions<WebsiteOptions> options, [FromQuery] string? id)
2223
{
2324
var interval = Random.Shared.Next(1, 2000);
2425
await Task.Delay(interval);
26+
2527
#if DEBUG
26-
var fileName = Path.Combine(env.WebRootPath, "../../");
28+
var fileName = Path.Combine(options.Value.WebRootPath, "../../BootstrapBlazor.Shared/wwwroot/images/waterfall", $"{id}.jpeg");
2729
#else
28-
var fileName = Path.Combine(AppContext.BaseDirectory, "_content");
30+
var fileName = Path.Combine(options.Value.WebRootPath, "_content/BootstrapBlazor.Shared/wwwroot/images/waterfall", $"{id}.jpeg");
2931
#endif
30-
fileName = Path.Combine(fileName, "BootstrapBlazor.Shared/wwwroot/images/waterfall", $"{id}.jpeg");
3132
return new PhysicalFileResult(fileName, "images/jpeg");
3233
}
3334
}

src/BootstrapBlazor.Server/Extensions/StaticFileResponseContextExtensions.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,8 @@ public static RenderFragment RenderAssets(this ComponentBase component) => build
3636
var v = pi.GetValue(component);
3737
if (v is ResourceAssetCollection assets)
3838
{
39-
builder.RenderCss($"{assets["_content/BootstrapBlazor.AntDesignIcon/BootstrapBlazor.AntDesignIcon.bundle.scp.css"]}");
40-
builder.RenderCss($"{assets["_content/BootstrapBlazor.BootstrapIcon/css/bootstrap.min.css"]}");
41-
builder.RenderCss($"{assets["_content/BootstrapBlazor.ElementIcon/BootstrapBlazor.ElementIcon.bundle.scp.css"]}");
4239
builder.RenderCss($"{assets["_content/BootstrapBlazor.FontAwesome/css/font-awesome.min.css"]}");
4340
builder.RenderCss($"{assets["_content/BootstrapBlazor.MaterialDesign/css/md.min.css"]}");
44-
builder.RenderCss($"{assets["_content/BootstrapBlazor.IconPark/BootstrapBlazor.IconPark.bundle.scp.css"]}");
4541
builder.RenderCss($"{assets["_content/BootstrapBlazor/css/bootstrap.blazor.bundle.min.css"]}");
4642
builder.RenderCss($"{assets["_content/BootstrapBlazor/css/motronic.min.css"]}");
4743
builder.RenderCss($"{assets["_content/BootstrapBlazor.Shared/BootstrapBlazor.Shared.bundle.scp.css"]}");

src/BootstrapBlazor.Server/Services/ClearUploadFilesService.cs

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,14 @@
44
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
55

66
using Longbow.Tasks;
7-
using Microsoft.Extensions.Options;
87

98
namespace BootstrapBlazor.Service.Services;
109

1110
/// <summary>
1211
/// 后台任务服务类
1312
/// </summary>
14-
internal class ClearTempFilesService : BackgroundService
13+
internal class ClearTempFilesService(IWebHostEnvironment env) : BackgroundService
1514
{
16-
private readonly IWebHostEnvironment _env;
17-
18-
/// <summary>
19-
///
20-
/// </summary>
21-
/// <param name="env"></param>
22-
/// <param name="websiteOption"></param>
23-
public ClearTempFilesService(IWebHostEnvironment env, IOptionsMonitor<WebsiteOptions> websiteOption)
24-
{
25-
_env = env;
26-
websiteOption.CurrentValue.WebRootPath = env.WebRootPath;
27-
websiteOption.CurrentValue.ContentRootPath = env.ContentRootPath;
28-
websiteOption.CurrentValue.IsDevelopment = env.IsDevelopment();
29-
}
30-
3115
/// <summary>
3216
/// 运行任务
3317
/// </summary>
@@ -37,15 +21,14 @@ protected override Task ExecuteAsync(CancellationToken stoppingToken)
3721
{
3822
TaskServicesManager.GetOrAdd("Clear Upload Files", (provider, token) =>
3923
{
40-
var webSiteUrl = $"images{Path.DirectorySeparatorChar}uploader{Path.DirectorySeparatorChar}";
41-
var filePath = Path.Combine(_env.WebRootPath, webSiteUrl);
24+
var filePath = Path.Combine(env.WebRootPath, "images", "uploader");
4225
if (Directory.Exists(filePath))
4326
{
4427
Directory.EnumerateFiles(filePath).Take(10).ToList().ForEach(file => DeleteFile(file, token));
4528
}
4629

4730
// 清除导出临时文件
48-
var exportFilePath = Path.Combine(_env.WebRootPath, "pdf");
31+
var exportFilePath = Path.Combine(env.WebRootPath, "pdf");
4932
if (Directory.Exists(exportFilePath))
5033
{
5134
Directory.EnumerateFiles(exportFilePath, "*.html").Take(10).Where(file =>
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
<img alt="logo" class="bb-icon" src="./_content/BootstrapBlazor.Shared/images/logo.png" />
1+
@inject IOptionsMonitor<WebsiteOptions> WebsiteOption
2+
3+
<img alt="logo" class="bb-icon" src="@WebsiteOption.CurrentValue.GetAssetUrl("images/logo.png")" />

src/BootstrapBlazor.Shared/Components/Components/BlazorReconnector.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
<p></p>
7272
<div>已提供项目模板方便快速上手 <a class="connection-link" href="@TemplateUrl" target="_blank">项目模板</a></div>
7373
</div>
74-
<img altt="QQ" src="./_content/BootstrapBlazor.Shared/images/[email protected]" alt="QQGroup" />
74+
<img altt="QQ" src="@WebsiteOption.CurrentValue.GetAssetUrl("images/QQGroup@2x.png")" alt="QQGroup" />
7575
<div class="connection-body-tail d-none d-sm-block"></div>
7676
</div>
7777
</div>;

src/BootstrapBlazor.Shared/Components/Components/ComponentCard.razor.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
55

6+
using Microsoft.Extensions.Options;
7+
68
namespace BootstrapBlazor.Shared.Components.Components;
79

810
/// <summary>
911
///
1012
/// </summary>
1113
public sealed partial class ComponentCard
1214
{
13-
private string ImageUrl => $"./_content/BootstrapBlazor.Shared/images/{Image}";
15+
[Inject, NotNull]
16+
private IOptionsMonitor<WebsiteOptions>? WebsiteOption { get; set; }
17+
18+
private string ImageUrl => $"{WebsiteOption.CurrentValue.AssetRootPath}images/{Image}";
1419

1520
private string? ClassString => CssBuilder.Default("col-12 col-sm-6 col-md-4 col-lg-3")
1621
.AddClass("d-none", IsHide)

src/BootstrapBlazor.Shared/Components/Components/CustomWinBoxContent.razor

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<div class="bb-winbox-body">
1+
@inject IOptionsMonitor<WebsiteOptions> WebsiteOption
2+
3+
<div class="bb-winbox-body">
24
<h3>Custom WinBox Content Create @DateTime.Now</h3>
35
</div>
46

src/BootstrapBlazor.Shared/Components/Components/CustomWinBoxContent.razor.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
55

6+
using Microsoft.Extensions.Options;
7+
68
namespace BootstrapBlazor.Shared.Components.Components;
79

810
/// <summary>
@@ -49,7 +51,7 @@ private async Task SetIconWinBox()
4951
{
5052
if (Option != null)
5153
{
52-
Option.Icon = "./_content/BootstrapBlazor.Shared/images/Argo-C.png";
54+
Option.Icon = $"{WebsiteOption.CurrentValue.AssetRootPath}images/Argo-C.png";
5355
await WinBoxService.SetIcon(Option);
5456
}
5557
}

src/BootstrapBlazor.Shared/Components/Components/Header.razor

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@inherits WebSiteModuleComponentBase
2-
@attribute [JSModuleAutoLoader("../_content/BootstrapBlazor.Shared/Components/Components/Header.razor.js")]
2+
@attribute [JSModuleAutoLoader("Components/Header.razor.js")]
33

44
<header class="navbar-header navbar navbar-expand flex-column flex-md-row px-3">
55
<div class="header-img navbar-brand">
@@ -34,12 +34,12 @@
3434
<ul class="navbar-nav nav-repo ms-3">
3535
<li class="nav-item">
3636
<a class="nav-link p-2" href="@WebsiteOption.CurrentValue.GithubRepositoryUrl" target="_blank">
37-
<img alt="git" src="./_content/BootstrapBlazor.Shared/images/git.svg" />
37+
<img alt="git" src="@WebsiteOption.CurrentValue.GetAssetUrl("images/git.svg")" />
3838
</a>
3939
</li>
4040
<li class="nav-item">
4141
<a class="nav-link p-2" href="@WebsiteOption.CurrentValue.GiteeRepositoryUrl" target="_blank">
42-
<img alt="gitee" src="./_content/BootstrapBlazor.Shared/images/gitee.svg" />
42+
<img alt="gitee" src="@WebsiteOption.CurrentValue.GetAssetUrl("images/gitee.svg")" />
4343
</a>
4444
</li>
4545
<li class="nav-item">

0 commit comments

Comments
 (0)