add: 添加对于子路径的支持

This commit is contained in:
jackfiled 2024-02-15 20:21:52 +08:00
parent 2bfd65735f
commit c067f11be7
8 changed files with 33 additions and 23 deletions

View File

@ -9,6 +9,11 @@ public class BlogOptions
/// </summary>
public required string Root { get; set; }
/// <summary>
/// 博客挂载的子路径
/// </summary>
public required string SubPath { get; set; }
/// <summary>
/// 博客作者
/// </summary>

View File

@ -12,6 +12,8 @@ public class WebApplicationHostedService : IHostedService
private readonly List<Action<WebApplication>> _webApplicationConfigurations;
private readonly IOptions<BlogOptions> _options;
private Website? _currentWebsite;
public WebApplicationHostedService(List<Action<WebApplicationBuilder>> webApplicationBuilderConfigurations,
@ -19,6 +21,8 @@ public class WebApplicationHostedService : IHostedService
IServiceProvider hostServiceProvider)
{
_webApplicationConfigurations = webApplicationConfigurations;
_options = hostServiceProvider.GetRequiredService<IOptions<BlogOptions>>();
foreach (Action<WebApplicationBuilder> configure in webApplicationBuilderConfigurations)
{
configure(_websiteBuilder);
@ -35,6 +39,7 @@ public class WebApplicationHostedService : IHostedService
}
WebApplication application = _websiteBuilder.Build();
application.UsePathBase("/" + _options.Value.SubPath);
foreach (Action<WebApplication> configure in _webApplicationConfigurations)
{
configure(application);

View File

@ -7,7 +7,7 @@
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<base href="/"/>
<base href="/@(BlogOptionsInstance.SubPath)/"/>
<link href="@($"{BlogOptionsInstance.ProjectName}.styles.css")" rel="stylesheet"/>
<link href="_content/Microsoft.FluentUI.AspNetCore.Components/css/reboot.css" rel="stylesheet" />
<link href="_content/YaeBlog.Theme.FluentUI/globals.css" rel="stylesheet"/>

View File

@ -21,7 +21,7 @@
<FluentStack Orientation="@Orientation.Horizontal"
HorizontalAlignment="@HorizontalAlignment.Center"
HorizontalGap="20">
<a href="/archives">
<a href="archives">
<div>
<FluentLabel Typo="@Typography.H4">
文章
@ -32,7 +32,7 @@
</FluentLabel>
</div>
</a>
<a href="/tags">
<a href="tags">
<div>
<FluentLabel Typo="@Typography.H4">
标签

View File

@ -8,7 +8,7 @@
<FluentStack Orientation="@Orientation.Horizontal">
<div style="width: 50px"></div>
<a href="/">
<a href="./">
<FluentLabel Typo="@Typography.H3" Color="@Color.Lightweight">
@BlogOptionsInstance.Author
</FluentLabel>
@ -16,7 +16,7 @@
<FluentSpacer/>
<a href="/" style="margin: auto 0 auto 0">
<a href="./" style="margin: auto 0 auto 0">
<div class="quick-link">
<FluentIcon Value="@(new Icons.Regular.Size16.Home())" Color="@Color.Fill"/>
<FluentLabel Typo="@Typography.H5" Color="@Color.Lightweight"
@ -26,7 +26,7 @@
</div>
</a>
<a href="/archives" style="margin: auto 0 auto 0">
<a href="archives" style="margin: auto 0 auto 0">
<div class="quick-link">
<FluentIcon Value="@(new Icons.Regular.Size16.Archive())" Color="@Color.Fill"/>
<FluentLabel Typo="@Typography.H5" Color="@Color.Lightweight"
@ -36,7 +36,7 @@
</div>
</a>
<a href="/tags" style="margin: auto 0 auto 0">
<a href="tags" style="margin: auto 0 auto 0">
<div class="quick-link">
<FluentIcon Value="@(new Icons.Regular.Size16.Tag())" Color="@Color.Fill"/>
<FluentLabel Typo="@Typography.H5" Color="@Color.Lightweight"
@ -46,7 +46,7 @@
</div>
</a>
<a href="/about" style="margin: auto 0 auto 0">
<a href="about" style="margin: auto 0 auto 0">
<div class="quick-link">
<FluentIcon Value="@(new Icons.Regular.Size16.PersonInfo())" Color="@Color.Fill"/>
<FluentLabel Typo="@Typography.H5" Color="@Color.Lightweight"
@ -56,7 +56,7 @@
</div>
</a>
<a href="/links" style="margin: auto 0 auto 0">
<a href="links" style="margin: auto 0 auto 0">
<div class="quick-link">
<FluentIcon Value="@(new Icons.Regular.Size16.LinkMultiple())" Color="@Color.Fill"/>
<FluentLabel Typo="@Typography.H5" Color="@Color.Lightweight"

View File

@ -40,7 +40,7 @@
@foreach (KeyValuePair<string, BlogEssay> pair in group)
{
<div class="archive-item">
<a href="/essays/@(pair.Key)" target="_blank">
<a href="essays/@(pair.Key)" target="_blank">
<FluentStack Orientation="@Orientation.Horizontal">
<FluentLabel Typo="@Typography.H5" Style="width: 80px">
@(pair.Value.PublishTime.ToString("MM-dd"))

View File

@ -74,51 +74,51 @@
HorizontalGap="20">
@if (Page != 1)
{
<a href="/?page=@(Page - 1)#blog-content" class="pagination-item">
<a href="./?page=@(Page - 1)#blog-content" class="pagination-item">
<i class="chevron-left"></i>
</a>
}
@if (Page == 1)
{
<a href="/?page=1#blog-content" class="pagination-item">
<a href="./?page=1#blog-content" class="pagination-item">
<span>1</span>
</a>
<a href="/?page=2#blog-content" class="pagination-item">
<a href="./?page=2#blog-content" class="pagination-item">
<span>2</span>
</a>
<a href="/?page=3#blog-content" class="pagination-item">
<a href="./?page=3#blog-content" class="pagination-item">
<span>3</span>
</a>
}
else if (Page == _pageCount)
{
<a href="/?page=@(_pageCount - 2)#blog-content" class="pagination-item">
<a href="./?page=@(_pageCount - 2)#blog-content" class="pagination-item">
<span>@(_pageCount - 2)</span>
</a>
<a href="/?page=@(_pageCount - 1)#blog-content" class="pagination-item">
<a href="./?page=@(_pageCount - 1)#blog-content" class="pagination-item">
<span>@(_pageCount - 1)</span>
</a>
<a href="/?page=@(_pageCount)#blog-content" class="pagination-item">
<a href="./?page=@(_pageCount)#blog-content" class="pagination-item">
<span>@(_pageCount)</span>
</a>
}
else
{
<a href="/?page=@(Page - 1)#blog-content" class="pagination-item">
<a href="./?page=@(Page - 1)#blog-content" class="pagination-item">
<span>@(Page - 1)</span>
</a>
<a href="/?page=@(Page)#blog-content" class="pagination-item">
<a href="./?page=@(Page)#blog-content" class="pagination-item">
<span>@(Page)</span>
</a>
<a href="/?page=@(Page + 1)#blog-content" class="pagination-item">
<a href="./?page=@(Page + 1)#blog-content" class="pagination-item">
<span>@(Page + 1)</span>
</a>
}
@if (Page != _pageCount)
{
<a href="/?page=@(Page + 1)#blog-content" class="pagination-item">
<a href="./?page=@(Page + 1)#blog-content" class="pagination-item">
<i class="chevron-right"></i>
</a>
}

View File

@ -33,7 +33,7 @@
@foreach (KeyValuePair<string, int> pair in EssayContentInstance.Tags)
{
<div class="tag-item">
<a href="/tags?TagName=@(pair.Key)">
<a href="tags?TagName=@(pair.Key)">
<span style="font-size: @(14 + pair.Value)px; color: @(RandomColor())">
@pair.Key
</span>
@ -52,7 +52,7 @@
{
<div style="margin: 0 4% 0 4%">
<div class="tag-essay-item">
<a href="/essays/@(essay.FileName)" target="_blank">
<a href="essays/@(essay.FileName)" target="_blank">
<FluentStack Orientation="@Orientation.Horizontal">
<FluentLabel Typo="@Typography.H5" Style="width: 120px">
@(essay.PublishTime.ToString("yyyy-MM-dd"))