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" >
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 >
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 ();
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
6774 // 配置图片路径重写
6875 mudMarkdownProps .Link .OverrideUrl = (link ) =>
6976 {
77+
7078 // 检查这是否是一个图片链接
7179 if (link .IsImage )
7280 {
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 {
0 commit comments