add: 添加对于子路径的支持
This commit is contained in:
parent
2bfd65735f
commit
c067f11be7
|
@ -9,6 +9,11 @@ public class BlogOptions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public required string Root { get; set; }
|
public required string Root { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 博客挂载的子路径
|
||||||
|
/// </summary>
|
||||||
|
public required string SubPath { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 博客作者
|
/// 博客作者
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -12,6 +12,8 @@ public class WebApplicationHostedService : IHostedService
|
||||||
|
|
||||||
private readonly List<Action<WebApplication>> _webApplicationConfigurations;
|
private readonly List<Action<WebApplication>> _webApplicationConfigurations;
|
||||||
|
|
||||||
|
private readonly IOptions<BlogOptions> _options;
|
||||||
|
|
||||||
private Website? _currentWebsite;
|
private Website? _currentWebsite;
|
||||||
|
|
||||||
public WebApplicationHostedService(List<Action<WebApplicationBuilder>> webApplicationBuilderConfigurations,
|
public WebApplicationHostedService(List<Action<WebApplicationBuilder>> webApplicationBuilderConfigurations,
|
||||||
|
@ -19,6 +21,8 @@ public class WebApplicationHostedService : IHostedService
|
||||||
IServiceProvider hostServiceProvider)
|
IServiceProvider hostServiceProvider)
|
||||||
{
|
{
|
||||||
_webApplicationConfigurations = webApplicationConfigurations;
|
_webApplicationConfigurations = webApplicationConfigurations;
|
||||||
|
_options = hostServiceProvider.GetRequiredService<IOptions<BlogOptions>>();
|
||||||
|
|
||||||
foreach (Action<WebApplicationBuilder> configure in webApplicationBuilderConfigurations)
|
foreach (Action<WebApplicationBuilder> configure in webApplicationBuilderConfigurations)
|
||||||
{
|
{
|
||||||
configure(_websiteBuilder);
|
configure(_websiteBuilder);
|
||||||
|
@ -35,6 +39,7 @@ public class WebApplicationHostedService : IHostedService
|
||||||
}
|
}
|
||||||
|
|
||||||
WebApplication application = _websiteBuilder.Build();
|
WebApplication application = _websiteBuilder.Build();
|
||||||
|
application.UsePathBase("/" + _options.Value.SubPath);
|
||||||
foreach (Action<WebApplication> configure in _webApplicationConfigurations)
|
foreach (Action<WebApplication> configure in _webApplicationConfigurations)
|
||||||
{
|
{
|
||||||
configure(application);
|
configure(application);
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8"/>
|
<meta charset="utf-8"/>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
<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="@($"{BlogOptionsInstance.ProjectName}.styles.css")" rel="stylesheet"/>
|
||||||
<link href="_content/Microsoft.FluentUI.AspNetCore.Components/css/reboot.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"/>
|
<link href="_content/YaeBlog.Theme.FluentUI/globals.css" rel="stylesheet"/>
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
<FluentStack Orientation="@Orientation.Horizontal"
|
<FluentStack Orientation="@Orientation.Horizontal"
|
||||||
HorizontalAlignment="@HorizontalAlignment.Center"
|
HorizontalAlignment="@HorizontalAlignment.Center"
|
||||||
HorizontalGap="20">
|
HorizontalGap="20">
|
||||||
<a href="/archives">
|
<a href="archives">
|
||||||
<div>
|
<div>
|
||||||
<FluentLabel Typo="@Typography.H4">
|
<FluentLabel Typo="@Typography.H4">
|
||||||
文章
|
文章
|
||||||
|
@ -32,7 +32,7 @@
|
||||||
</FluentLabel>
|
</FluentLabel>
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
<a href="/tags">
|
<a href="tags">
|
||||||
<div>
|
<div>
|
||||||
<FluentLabel Typo="@Typography.H4">
|
<FluentLabel Typo="@Typography.H4">
|
||||||
标签
|
标签
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
<FluentStack Orientation="@Orientation.Horizontal">
|
<FluentStack Orientation="@Orientation.Horizontal">
|
||||||
<div style="width: 50px"></div>
|
<div style="width: 50px"></div>
|
||||||
|
|
||||||
<a href="/">
|
<a href="./">
|
||||||
<FluentLabel Typo="@Typography.H3" Color="@Color.Lightweight">
|
<FluentLabel Typo="@Typography.H3" Color="@Color.Lightweight">
|
||||||
@BlogOptionsInstance.Author
|
@BlogOptionsInstance.Author
|
||||||
</FluentLabel>
|
</FluentLabel>
|
||||||
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
<FluentSpacer/>
|
<FluentSpacer/>
|
||||||
|
|
||||||
<a href="/" style="margin: auto 0 auto 0">
|
<a href="./" style="margin: auto 0 auto 0">
|
||||||
<div class="quick-link">
|
<div class="quick-link">
|
||||||
<FluentIcon Value="@(new Icons.Regular.Size16.Home())" Color="@Color.Fill"/>
|
<FluentIcon Value="@(new Icons.Regular.Size16.Home())" Color="@Color.Fill"/>
|
||||||
<FluentLabel Typo="@Typography.H5" Color="@Color.Lightweight"
|
<FluentLabel Typo="@Typography.H5" Color="@Color.Lightweight"
|
||||||
|
@ -26,7 +26,7 @@
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<a href="/archives" style="margin: auto 0 auto 0">
|
<a href="archives" style="margin: auto 0 auto 0">
|
||||||
<div class="quick-link">
|
<div class="quick-link">
|
||||||
<FluentIcon Value="@(new Icons.Regular.Size16.Archive())" Color="@Color.Fill"/>
|
<FluentIcon Value="@(new Icons.Regular.Size16.Archive())" Color="@Color.Fill"/>
|
||||||
<FluentLabel Typo="@Typography.H5" Color="@Color.Lightweight"
|
<FluentLabel Typo="@Typography.H5" Color="@Color.Lightweight"
|
||||||
|
@ -36,7 +36,7 @@
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<a href="/tags" style="margin: auto 0 auto 0">
|
<a href="tags" style="margin: auto 0 auto 0">
|
||||||
<div class="quick-link">
|
<div class="quick-link">
|
||||||
<FluentIcon Value="@(new Icons.Regular.Size16.Tag())" Color="@Color.Fill"/>
|
<FluentIcon Value="@(new Icons.Regular.Size16.Tag())" Color="@Color.Fill"/>
|
||||||
<FluentLabel Typo="@Typography.H5" Color="@Color.Lightweight"
|
<FluentLabel Typo="@Typography.H5" Color="@Color.Lightweight"
|
||||||
|
@ -46,7 +46,7 @@
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<a href="/about" style="margin: auto 0 auto 0">
|
<a href="about" style="margin: auto 0 auto 0">
|
||||||
<div class="quick-link">
|
<div class="quick-link">
|
||||||
<FluentIcon Value="@(new Icons.Regular.Size16.PersonInfo())" Color="@Color.Fill"/>
|
<FluentIcon Value="@(new Icons.Regular.Size16.PersonInfo())" Color="@Color.Fill"/>
|
||||||
<FluentLabel Typo="@Typography.H5" Color="@Color.Lightweight"
|
<FluentLabel Typo="@Typography.H5" Color="@Color.Lightweight"
|
||||||
|
@ -56,7 +56,7 @@
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<a href="/links" style="margin: auto 0 auto 0">
|
<a href="links" style="margin: auto 0 auto 0">
|
||||||
<div class="quick-link">
|
<div class="quick-link">
|
||||||
<FluentIcon Value="@(new Icons.Regular.Size16.LinkMultiple())" Color="@Color.Fill"/>
|
<FluentIcon Value="@(new Icons.Regular.Size16.LinkMultiple())" Color="@Color.Fill"/>
|
||||||
<FluentLabel Typo="@Typography.H5" Color="@Color.Lightweight"
|
<FluentLabel Typo="@Typography.H5" Color="@Color.Lightweight"
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
@foreach (KeyValuePair<string, BlogEssay> pair in group)
|
@foreach (KeyValuePair<string, BlogEssay> pair in group)
|
||||||
{
|
{
|
||||||
<div class="archive-item">
|
<div class="archive-item">
|
||||||
<a href="/essays/@(pair.Key)" target="_blank">
|
<a href="essays/@(pair.Key)" target="_blank">
|
||||||
<FluentStack Orientation="@Orientation.Horizontal">
|
<FluentStack Orientation="@Orientation.Horizontal">
|
||||||
<FluentLabel Typo="@Typography.H5" Style="width: 80px">
|
<FluentLabel Typo="@Typography.H5" Style="width: 80px">
|
||||||
@(pair.Value.PublishTime.ToString("MM-dd"))
|
@(pair.Value.PublishTime.ToString("MM-dd"))
|
||||||
|
|
|
@ -74,51 +74,51 @@
|
||||||
HorizontalGap="20">
|
HorizontalGap="20">
|
||||||
@if (Page != 1)
|
@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>
|
<i class="chevron-left"></i>
|
||||||
</a>
|
</a>
|
||||||
}
|
}
|
||||||
|
|
||||||
@if (Page == 1)
|
@if (Page == 1)
|
||||||
{
|
{
|
||||||
<a href="/?page=1#blog-content" class="pagination-item">
|
<a href="./?page=1#blog-content" class="pagination-item">
|
||||||
<span>1</span>
|
<span>1</span>
|
||||||
</a>
|
</a>
|
||||||
<a href="/?page=2#blog-content" class="pagination-item">
|
<a href="./?page=2#blog-content" class="pagination-item">
|
||||||
<span>2</span>
|
<span>2</span>
|
||||||
</a>
|
</a>
|
||||||
<a href="/?page=3#blog-content" class="pagination-item">
|
<a href="./?page=3#blog-content" class="pagination-item">
|
||||||
<span>3</span>
|
<span>3</span>
|
||||||
</a>
|
</a>
|
||||||
}
|
}
|
||||||
else if (Page == _pageCount)
|
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>
|
<span>@(_pageCount - 2)</span>
|
||||||
</a>
|
</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>
|
<span>@(_pageCount - 1)</span>
|
||||||
</a>
|
</a>
|
||||||
<a href="/?page=@(_pageCount)#blog-content" class="pagination-item">
|
<a href="./?page=@(_pageCount)#blog-content" class="pagination-item">
|
||||||
<span>@(_pageCount)</span>
|
<span>@(_pageCount)</span>
|
||||||
</a>
|
</a>
|
||||||
}
|
}
|
||||||
else
|
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>
|
<span>@(Page - 1)</span>
|
||||||
</a>
|
</a>
|
||||||
<a href="/?page=@(Page)#blog-content" class="pagination-item">
|
<a href="./?page=@(Page)#blog-content" class="pagination-item">
|
||||||
<span>@(Page)</span>
|
<span>@(Page)</span>
|
||||||
</a>
|
</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>
|
<span>@(Page + 1)</span>
|
||||||
</a>
|
</a>
|
||||||
}
|
}
|
||||||
|
|
||||||
@if (Page != _pageCount)
|
@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>
|
<i class="chevron-right"></i>
|
||||||
</a>
|
</a>
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
@foreach (KeyValuePair<string, int> pair in EssayContentInstance.Tags)
|
@foreach (KeyValuePair<string, int> pair in EssayContentInstance.Tags)
|
||||||
{
|
{
|
||||||
<div class="tag-item">
|
<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())">
|
<span style="font-size: @(14 + pair.Value)px; color: @(RandomColor())">
|
||||||
@pair.Key
|
@pair.Key
|
||||||
</span>
|
</span>
|
||||||
|
@ -52,7 +52,7 @@
|
||||||
{
|
{
|
||||||
<div style="margin: 0 4% 0 4%">
|
<div style="margin: 0 4% 0 4%">
|
||||||
<div class="tag-essay-item">
|
<div class="tag-essay-item">
|
||||||
<a href="/essays/@(essay.FileName)" target="_blank">
|
<a href="essays/@(essay.FileName)" target="_blank">
|
||||||
<FluentStack Orientation="@Orientation.Horizontal">
|
<FluentStack Orientation="@Orientation.Horizontal">
|
||||||
<FluentLabel Typo="@Typography.H5" Style="width: 120px">
|
<FluentLabel Typo="@Typography.H5" Style="width: 120px">
|
||||||
@(essay.PublishTime.ToString("yyyy-MM-dd"))
|
@(essay.PublishTime.ToString("yyyy-MM-dd"))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user