Skip to content

Commit f94a93d

Browse files
committed
Make StructuredData part of OgData
1 parent f0a79cd commit f94a93d

File tree

4 files changed

+21
-15
lines changed

4 files changed

+21
-15
lines changed

src/LinkDotNet.Blog.Web/Features/Components/OgData.razor

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,26 @@
33
<HeadContent>
44
<meta name="title" property="og:title" content="@Title" />
55
<link rel="canonical" href="@GetCanoncialUri()" />
6-
@if (AbsolutePreviewImageUrl != null)
6+
@if (AbsolutePreviewImageUrl is not null)
77
{
88
<meta name="image" property="og:image" content="@AbsolutePreviewImageUrl"/>
99
}
1010
<meta property="og:type" content="article" />
1111
<meta property="og:url" content="@NavigationManager.Uri" />
12-
@if (Keywords != null)
12+
@if (Keywords is not null)
1313
{
1414
<meta name="keywords" content="@Keywords"/>
1515
}
16-
@if (Description != null)
16+
@if (Description is not null)
1717
{
1818
<meta name="description" property="og:description" content="@Description" />
1919
}
20+
21+
@if (ChildContent is not null)
22+
{
23+
@ChildContent
24+
}
25+
2026
</HeadContent>
2127
@code {
2228

@@ -32,7 +38,10 @@
3238
[Parameter]
3339
public string Keywords { get; set; }
3440

35-
private string GetCanoncialUri()
41+
[Parameter]
42+
public RenderFragment ChildContent { get; set; }
43+
44+
private string GetCanoncialUri()
3645
{
3746
var uri = new Uri(NavigationManager.Uri);
3847
return uri.GetLeftPart(UriPartial.Path);

src/LinkDotNet.Blog.Web/Features/ShowBlogPost/Components/StructuredData.razor

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
@using System.Text.Json
22
@using System.Text.Json.Serialization
33

4-
<HeadContent>
5-
<script suppress-error="BL9992" type="application/ld+json">@StructuredDataJson</script>
6-
</HeadContent>
4+
<script suppress-error="BL9992" type="application/ld+json">@StructuredDataJson</script>
75

86
@code {
97
[Parameter]

src/LinkDotNet.Blog.Web/Features/ShowBlogPost/ShowBlogPostPage.razor

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ else
1919
<OgData Title="@BlogPost.Title"
2020
AbsolutePreviewImageUrl="@OgDataImage"
2121
Description="@(Markdown.ToPlainText(BlogPost.ShortDescription))"
22-
Keywords="@BlogPost.TagsAsString"></OgData>
23-
<StructuredData Headline="@BlogPost.Title"
24-
PreviewImage="@BlogPost.PreviewImageUrl"
25-
PreviewFallbackImage="@BlogPost.PreviewImageUrlFallback"
26-
PublishedDate="@BlogPost.UpdatedDate"
27-
Author="@AppConfiguration.ProfileInformation?.Name"/>
22+
Keywords="@BlogPost.TagsAsString">
23+
<StructuredData Headline="@BlogPost.Title"
24+
PreviewImage="@BlogPost.PreviewImageUrl"
25+
PreviewFallbackImage="@BlogPost.PreviewImageUrlFallback"
26+
PublishedDate="@BlogPost.UpdatedDate"
27+
Author="@AppConfiguration.ProfileInformation?.Name"/>
28+
</OgData>
2829

2930
<div class="d-flex justify-content-center pt-2 blog-outer-box">
3031
<div class="content blog-container">

tests/LinkDotNet.Blog.UnitTests/Web/Features/ShowBlogPost/Components/StructuredDataTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ public class StructuredDataTests : TestContext
88
[Fact]
99
public void ShouldRenderRawMarkup()
1010
{
11-
ComponentFactories.AddStub<HeadContent>(ps => ps.Get(p => p.ChildContent));
12-
1311
var cut = RenderComponent<StructuredData>(
1412
ps => ps.Add(p => p.Author, "Steven")
1513
.Add(p => p.Headline, "Headline")

0 commit comments

Comments
 (0)