Skip to content

Commit 97a070a

Browse files
authored
Merge pull request #106 from codemonkey85/dev
Dev
2 parents 5f57e65 + 066e9d5 commit 97a070a

4 files changed

Lines changed: 77 additions & 16 deletions

File tree

AboutMe/Wasm/GlobalUsings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
global using Humanizer;
44
global using Microsoft.AspNetCore.Components.Web;
55
global using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
6+
global using Microsoft.JSInterop;
67
global using MudBlazor;
78
global using MudBlazor.Services;
89
global using System.Diagnostics.CodeAnalysis;

AboutMe/Wasm/Pages/Blog.razor

Lines changed: 62 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,29 @@ else
4040
@foreach (var post in Posts)
4141
{
4242
<MudCard>
43-
<MudCardHeader>
44-
<MudText Typo="Typo.h6">
45-
<a href="@post.Url"
46-
target="_blank">
47-
@post.Title
48-
</a>
49-
</MudText>
50-
</MudCardHeader>
43+
@if (!string.IsNullOrEmpty(post.Title))
44+
{
45+
<MudCardHeader>
46+
<MudText Typo="Typo.h6">
47+
<MudLink Href="@post.Url"
48+
Class="bold-text"
49+
Target="_blank">
50+
@post.Title
51+
</MudLink>
52+
</MudText>
53+
</MudCardHeader>
54+
}
5155
<MudCardContent>
5256
<div class="content-wrapper">
5357
@(new MarkupString(post.ContentHtml))
5458
</div>
5559
</MudCardContent>
5660
<MudCardActions>
5761
<MudText Typo="Typo.subtitle2">
58-
<a href="@post.Url"
59-
target="_blank">
62+
<MudLink Href="@post.Url"
63+
Target="_blank">
6064
@post.DatePublished.ToLocalTime().ToString(DateFormat)
61-
</a>
65+
</MudLink>
6266
</MudText>
6367
</MudCardActions>
6468
</MudCard>
@@ -68,8 +72,54 @@ else
6872

6973
<style>
7074
.content-wrapper img {
71-
max-width: 100%;
75+
max-width: 400px;
76+
width: 100%;
7277
height: auto;
7378
display: block;
7479
}
80+
81+
.content-wrapper p {
82+
margin-bottom: 1rem;
83+
}
84+
85+
.content-wrapper a {
86+
color: var(--mud-palette-primary);
87+
text-decoration: underline;
88+
}
89+
90+
.content-wrapper h1, .content-wrapper h2, .content-wrapper h3 {
91+
margin-top: 1.5rem;
92+
margin-bottom: 1rem;
93+
}
94+
95+
.content-wrapper ul, .content-wrapper ol {
96+
margin-bottom: 1rem;
97+
padding-left: 2rem;
98+
}
99+
100+
.content-wrapper code {
101+
background-color: var(--mud-palette-background-grey);
102+
padding: 0.2rem 0.4rem;
103+
border-radius: 3px;
104+
font-family: monospace;
105+
}
106+
107+
.content-wrapper pre {
108+
background-color: var(--mud-palette-background-grey);
109+
padding: 1rem;
110+
border-radius: 4px;
111+
overflow-x: auto;
112+
margin-bottom: 1rem;
113+
}
114+
115+
.content-wrapper blockquote {
116+
border-left: 4px solid var(--mud-palette-primary);
117+
padding-left: 1rem;
118+
margin: 1rem 0;
119+
font-style: italic;
120+
}
121+
122+
.bold-text {
123+
font-weight: bold;
124+
}
75125
</style>

AboutMe/Wasm/Pages/Blog.razor.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
// ReSharper disable once UnusedType.Global
44
// ReSharper disable once ClassNeverInstantiated.Global
5-
public partial class Blog(HttpClient httpClient)
5+
public partial class Blog(HttpClient httpClient, IJSRuntime jsRuntime)
66
{
77
[StringSyntax(StringSyntaxAttribute.DateTimeFormat)]
8-
private const string DateFormat = "ddd MMM dd yyyy hh:mm tt";
8+
private const string DateFormat = "dddd, MMMM dd, yyyy 'at' hh:mm tt";
99

1010
private static readonly JsonSerializerOptions JsonSerializerOptions =
1111
new()
@@ -41,6 +41,18 @@ protected override async Task OnInitializedAsync()
4141
}
4242
}
4343

44+
protected override async Task OnAfterRenderAsync(bool firstRender)
45+
{
46+
await base.OnAfterRenderAsync(firstRender);
47+
48+
if (!IsLoading && Posts.Count > 0)
49+
{
50+
await jsRuntime.InvokeVoidAsync("eval", "Array.from(document.querySelectorAll('a')).forEach(a => a.setAttribute('target', '_blank'))");
51+
await jsRuntime.InvokeVoidAsync("eval",
52+
"document.querySelectorAll('.content-wrapper a').forEach(a => { a.target = '_blank'; a.rel = 'noopener noreferrer'; });");
53+
}
54+
}
55+
4456
[JsonSerializable(typeof(Feed[]))]
4557
// ReSharper disable once ClassNeverInstantiated.Global
4658
private partial class FeedJsonContext : JsonSerializerContext;

AboutMe/Wasm/wwwroot/index.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
<link id="webassembly"
2626
rel="preload"/>
2727
<script type="importmap"></script>
28-
<!-- If you add any scoped CSS files, uncomment the following to load them
29-
<link href="AboutMe.Wasm.styles.css" rel="stylesheet"/> -->
3028
</head>
3129

3230
<body>

0 commit comments

Comments
 (0)