Skip to content

Commit

Permalink
Make StructuredData part of OgData
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdotnet committed Jul 31, 2023
1 parent f0a79cd commit f94a93d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
17 changes: 13 additions & 4 deletions src/LinkDotNet.Blog.Web/Features/Components/OgData.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,26 @@
<HeadContent>
<meta name="title" property="og:title" content="@Title" />
<link rel="canonical" href="@GetCanoncialUri()" />
@if (AbsolutePreviewImageUrl != null)
@if (AbsolutePreviewImageUrl is not null)
{
<meta name="image" property="og:image" content="@AbsolutePreviewImageUrl"/>
}
<meta property="og:type" content="article" />
<meta property="og:url" content="@NavigationManager.Uri" />
@if (Keywords != null)
@if (Keywords is not null)
{
<meta name="keywords" content="@Keywords"/>
}
@if (Description != null)
@if (Description is not null)
{
<meta name="description" property="og:description" content="@Description" />
}

@if (ChildContent is not null)
{
@ChildContent
}

</HeadContent>
@code {

Expand All @@ -32,7 +38,10 @@
[Parameter]
public string Keywords { get; set; }

private string GetCanoncialUri()
[Parameter]
public RenderFragment ChildContent { get; set; }

private string GetCanoncialUri()
{
var uri = new Uri(NavigationManager.Uri);
return uri.GetLeftPart(UriPartial.Path);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
@using System.Text.Json
@using System.Text.Json.Serialization

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

@code {
[Parameter]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ else
<OgData Title="@BlogPost.Title"
AbsolutePreviewImageUrl="@OgDataImage"
Description="@(Markdown.ToPlainText(BlogPost.ShortDescription))"
Keywords="@BlogPost.TagsAsString"></OgData>
<StructuredData Headline="@BlogPost.Title"
PreviewImage="@BlogPost.PreviewImageUrl"
PreviewFallbackImage="@BlogPost.PreviewImageUrlFallback"
PublishedDate="@BlogPost.UpdatedDate"
Author="@AppConfiguration.ProfileInformation?.Name"/>
Keywords="@BlogPost.TagsAsString">
<StructuredData Headline="@BlogPost.Title"
PreviewImage="@BlogPost.PreviewImageUrl"
PreviewFallbackImage="@BlogPost.PreviewImageUrlFallback"
PublishedDate="@BlogPost.UpdatedDate"
Author="@AppConfiguration.ProfileInformation?.Name"/>
</OgData>

<div class="d-flex justify-content-center pt-2 blog-outer-box">
<div class="content blog-container">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ public class StructuredDataTests : TestContext
[Fact]
public void ShouldRenderRawMarkup()
{
ComponentFactories.AddStub<HeadContent>(ps => ps.Get(p => p.ChildContent));

var cut = RenderComponent<StructuredData>(
ps => ps.Add(p => p.Author, "Steven")
.Add(p => p.Headline, "Headline")
Expand Down

0 comments on commit f94a93d

Please sign in to comment.