Skip to content

Commit 6194723

Browse files
committed
Added some more tags for SEO
1 parent bf54699 commit 6194723

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
<HeadContent>
44
<meta name="title" property="og:title" content="@Title" />
5+
<link rel="canonical" href="@NavigationManager.Uri" />
56
@if (AbsolutePreviewImageUrl != null)
67
{
78
<meta name="image" property="og:image" content="@AbsolutePreviewImageUrl"/>

src/LinkDotNet.Blog.Web/Features/Home/Components/AccessControl.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<li class="nav-item"><a class="nav-link" href="logout?redirectUri=@CurrentUri"><i class="lock"></i> Log out</a></li>
2323
</Authorized>
2424
<NotAuthorized>
25-
<li class="nav-item"><a class="nav-link" href="login?redirectUri=@CurrentUri"><i class="unlocked"></i> Log in</a></li>
25+
<li class="nav-item"><a class="nav-link" href="login?redirectUri=@CurrentUri" rel="nofollow"><i class="unlocked"></i> Log in</a></li>
2626
</NotAuthorized>
2727
</AuthorizeView>
2828

tests/LinkDotNet.Blog.UnitTests/Web/Features/Components/OgDataTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System.Linq;
22
using AngleSharp.Html.Dom;
33
using LinkDotNet.Blog.Web.Features.Components;
4+
using Microsoft.AspNetCore.Components;
45
using Microsoft.AspNetCore.Components.Web;
6+
using Microsoft.Extensions.DependencyInjection;
57

68
namespace LinkDotNet.Blog.UnitTests.Web.Features.Components;
79

@@ -37,6 +39,19 @@ public void ShouldNotSetMetaInformationWhenNotProvided()
3739
GetMetaTagExists(cut, "description").Should().BeFalse();
3840
}
3941

42+
[Fact]
43+
public void ShouldSetCanoncialLink()
44+
{
45+
ComponentFactories.AddStub<HeadContent>(ps => ps.Get(p => p.ChildContent));
46+
47+
var cut = RenderComponent<OgData>(p => p
48+
.Add(s => s.Title, "Title"));
49+
50+
var link = cut.FindAll("link").FirstOrDefault(l => l.Attributes.Any(a => a.Name == "rel" && a.Value == "canonical")) as IHtmlLinkElement;
51+
var expectedUri = Services.GetRequiredService<NavigationManager>().Uri;
52+
link.Href.Should().Be(expectedUri);
53+
}
54+
4055
private static void AssertMetaTagExistsWithValue(
4156
IRenderedFragment cut,
4257
string metaTag,

0 commit comments

Comments
 (0)