Skip to content

Commit 906aa7d

Browse files
committed
ww
1 parent ca2cb09 commit 906aa7d

File tree

3 files changed

+22
-30
lines changed

3 files changed

+22
-30
lines changed

OusePersonalWeb/Pages/Blog.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
private void OpenPost(string path)
6565
{
6666
// 传递 path 给详情页,注意 URL 编码
67-
Navigation.NavigateTo($"/blogContent?url={Uri.EscapeDataString(path)}");
67+
Navigation.NavigateTo($"/blogContent/{path}");
6868
}
6969

7070
public class BlogPost {

OusePersonalWeb/Pages/BlogContent.razor

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
@page "/blogContent"
1+
@page "/blogContent/{*BlogUrl}"
22
@using Blazored.LocalStorage
33
@using MudBlazor.Services
44
@inject NavigationManager Navigation
55
@inject ISnackbar Snackbar
66
@inject ILocalStorageService localStorage
7-
@inject IBrowserViewportService BrowserViewportService
8-
@implements IAsyncDisposable
97
@if (string.IsNullOrEmpty(fullUrl))
108
{
119
<div style="width:100%;height:100vh" class="d-flex flex-column justify-center align-center">
@@ -16,12 +14,22 @@ else
1614
{
1715
<div class="d-flex gap-4">
1816
<MudContainer MaxWidth="MaxWidth.Large" Class="py-8">
19-
<MudMarkdown Value="@fullUrl"
20-
TableOfContentsHeader="目录"
21-
HasTableOfContents="@(_currentBrowserWindowSize.Width>600?true:false)"
22-
Props="mudMarkdownProps"
23-
SourceType="MarkdownSourceType.Url"
24-
Styling="@mudMarkdownStyling" />
17+
<MudHidden Hidden Breakpoint="Breakpoint.SmAndDown">
18+
<MudMarkdown Value="@fullUrl"
19+
TableOfContentsHeader="目录"
20+
HasTableOfContents
21+
Props="mudMarkdownProps"
22+
SourceType="MarkdownSourceType.Url"
23+
Styling="@mudMarkdownStyling" />
24+
</MudHidden>
25+
<MudHidden Hidden Breakpoint="Breakpoint.MdAndUp">
26+
<MudMarkdown Value="@fullUrl"
27+
TableOfContentsHeader="目录"
28+
HasTableOfContents="false"
29+
Props="mudMarkdownProps"
30+
SourceType="MarkdownSourceType.Url"
31+
Styling="@mudMarkdownStyling" />
32+
</MudHidden>
2533
</MudContainer>
2634

2735
</div>
@@ -39,7 +47,7 @@ else
3947
</style>
4048

4149
@code {
42-
[SupplyParameterFromQuery(Name = "url")]
50+
[Parameter]
4351
public string BlogUrl { get; set; } = string.Empty;
4452
private readonly Guid _observerId = Guid.NewGuid();
4553
private BrowserWindowSize _currentBrowserWindowSize = new();
@@ -55,7 +63,6 @@ else
5563
mudMarkdownStyling.CodeBlock.Theme = CodeBlock;
5664
mudMarkdownStyling.CodeBlock.CopyButton = CodeBlockCopyButton.Sticky;
5765
mudMarkdownStyling.CodeBlock.CopyButtonText = "复制";
58-
5966
mudMarkdownProps.Heading.OverrideTypo = typo => typo switch
6067
{
6168
Typo.h1 => Typo.h4, // # 映射为 h4
@@ -67,6 +74,7 @@ else
6774
// 配置图片路径重写
6875
mudMarkdownProps.Link.OverrideUrl = (link) =>
6976
{
77+
7078
// 检查这是否是一个图片链接
7179
if (link.IsImage)
7280
{
@@ -84,7 +92,7 @@ else
8492
// 拼接成完整的 GitHub Raw 路径
8593
// Settings.BlogRawRoot 结尾已有 /,folderPath 结尾已有 /
8694
// 最终结果如: https://raw.githubusercontent.com/.../main/Dotnet/assets/1.png
87-
Console.WriteLine(originalUrl);
95+
//Console.WriteLine(originalUrl);
8896
return $"{Settings.BlogRawRoot}{folderPath}{originalUrl}";
8997
}
9098

@@ -100,23 +108,7 @@ else
100108
// 拼接 main 分支的原始文件地址
101109
fullUrl = $"{Settings.BlogRawRoot}{BlogUrl}";
102110
}
103-
protected override async Task OnAfterRenderAsync(bool firstRender)
104-
{
105-
if (firstRender)
106-
{
107-
await BrowserViewportService.SubscribeAsync(_observerId, async args =>
108-
{
109-
_currentBrowserWindowSize = args.BrowserWindowSize;
110-
await InvokeAsync(StateHasChanged);
111-
});
112-
}
113-
}
114111

115-
public async ValueTask DisposeAsync()
116-
{
117-
await BrowserViewportService.DisposeAsync();
118-
await BrowserViewportService.DisposeAsync();
119-
}
120112

121113
private async Task SaveTheme()
122114
{

OusePersonalWeb/Pages/Home.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
{
141141
if (string.IsNullOrWhiteSpace(selectedPost?.path))
142142
return;
143-
Navigation.NavigateTo($"/blogContent?url={Uri.EscapeDataString(selectedPost.path)}");
143+
Navigation.NavigateTo($"/blogContent/{selectedPost.path}");
144144
}
145145

146146
protected override async Task OnInitializedAsync()

0 commit comments

Comments
 (0)