Skip to content

Commit 9713a45

Browse files
committed
OpenGraph Metadata Component
1 parent 788f296 commit 9713a45

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

LinkDotNet.Blog.Web/Pages/BlogPostPage.razor

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
@page "/BlogPost/{blogPostId}"
22
@using LinkDotNet.Domain
33
@using LinkDotNet.Infrastructure.Persistence
4-
@using Microsoft.AspNetCore.Components.Web.Extensions.Head
54
@inject IRepository _repository
65
@inherits MarkdownComponentBase
76

@@ -11,8 +10,7 @@
1110
}
1211
else
1312
{
14-
<Meta property="og:title" content="@BlogPost.Title" />
15-
<Meta property="og:image" content="@BlogPost.PreviewImageUrl" />
13+
<OgData Title="@BlogPost.Title" PreviewImageUrl="@BlogPost.PreviewImageUrl"></OgData>
1614
<div class="blog-outer-box">
1715
<div class="content blog-container">
1816
<div class="blog-content">

LinkDotNet.Blog.Web/Pages/Index.razor

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
@page "/"
22
@using LinkDotNet.Domain
33
@using LinkDotNet.Infrastructure.Persistence
4+
@using Markdig
45
@inject IRepository _repository
56
@inject AppConfiguration _appConfiguration
67

8+
<OgData Title="@(Markdown.ToPlainText(_appConfiguration.Introduction.Description))" PreviewImageUrl="@_appConfiguration.Introduction.BackgroundUrl"></OgData>
9+
710
<IntroductionCard Introduction="_appConfiguration.Introduction"></IntroductionCard>
811

912
<div class="content px-4">
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@using Microsoft.AspNetCore.Components.Web.Extensions.Head
2+
@inject NavigationManager _navigationManager
3+
4+
<Meta property="og:title" content="@Title" />
5+
<Meta name="image" property="og:image" content="@PreviewImageUrl" />
6+
<Meta property="og:type" content="article" />
7+
<Meta property="og:url" content="@_navigationManager.Uri" />
8+
9+
@code {
10+
11+
[Parameter]
12+
public string Title { get; set; }
13+
14+
[Parameter]
15+
public string PreviewImageUrl { get; set; }
16+
17+
}

0 commit comments

Comments
 (0)