Skip to content

Commit ec102aa

Browse files
committed
Should Set Tags as Keyword
1 parent 47452d8 commit ec102aa

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

LinkDotNet.Blog.IntegrationTests/Web/Pages/BlogPostPageTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,24 @@ public async Task ShouldSubtractLikeOnEvent()
6363
var fromDb = await DbContext.BlogPosts.AsNoTracking().SingleAsync(d => d.Id == publishedPost.Id);
6464
fromDb.Likes.Should().Be(1);
6565
}
66+
67+
[Fact]
68+
public async Task ShouldSetTagsWhenAvailable()
69+
{
70+
var publishedPost = new BlogPostBuilder().IsPublished().WithTags("Tag1,Tag2").Build();
71+
await BlogPostRepository.StoreAsync(publishedPost);
72+
using var ctx = new TestContext();
73+
ctx.JSInterop.Mode = JSRuntimeMode.Loose;
74+
ctx.AddTestAuthorization();
75+
ctx.Services.AddScoped<IRepository>(_ => BlogPostRepository);
76+
ctx.Services.AddScoped(_ => new Mock<ILocalStorageService>().Object);
77+
ctx.Services.AddScoped(_ => new Mock<IToastService>().Object);
78+
var cut = ctx.RenderComponent<BlogPostPage>(
79+
p => p.Add(b => b.BlogPostId, publishedPost.Id));
80+
81+
var ogData = cut.FindComponent<OgData>();
82+
83+
ogData.Instance.Keywords.Should().Be("Tag1,Tag2");
84+
}
6685
}
6786
}

LinkDotNet.Blog.Web/Pages/BlogPostPage.razor

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
else
1515
{
1616
<Title Value="@BlogPost.Title"></Title>
17-
<OgData Title="@BlogPost.Title" AbsolutePreviewImageUrl="@BlogPost.PreviewImageUrl" Description="@(Markdown.ToPlainText(BlogPost.ShortDescription))"></OgData>
17+
<OgData Title="@BlogPost.Title"
18+
AbsolutePreviewImageUrl="@BlogPost.PreviewImageUrl"
19+
Description="@(Markdown.ToPlainText(BlogPost.ShortDescription))"
20+
Keywords="@Tags"></OgData>
1821
<div class="blog-outer-box">
1922
<div class="content blog-container">
2023
<div class="blog-content">
@@ -41,6 +44,10 @@ else
4144
[Parameter]
4245
public string BlogPostId { get; set; }
4346

47+
private string Tags => BlogPost?.Tags != null
48+
? string.Join(",", BlogPost.Tags.Select(b => b.Content))
49+
: null;
50+
4451
private BlogPost BlogPost { get; set; }
4552

4653
protected override async Task OnInitializedAsync()

LinkDotNet.Blog.Web/Shared/OgData.razor

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
<Meta name="image" property="og:image" content="@AbsolutePreviewImageUrl" />
66
<Meta property="og:type" content="article" />
77
<Meta property="og:url" content="@_navigationManager.Uri" />
8+
@if (Keywords != null)
9+
{
10+
<Meta name="keywords" content="@Keywords"/>
11+
}
812
@if (Description != null)
913
{
1014
<Meta name="description" property="og:description" content="@Description" />
@@ -20,4 +24,7 @@
2024

2125
[Parameter]
2226
public string Description { get; set; }
27+
28+
[Parameter]
29+
public string Keywords { get; set; }
2330
}

0 commit comments

Comments
 (0)