Skip to content

Commit c3e1240

Browse files
authored
Add og meta tags (#785)
* Add og meta tags * Add og:image:alt tag
1 parent f751243 commit c3e1240

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/Elastic.Markdown/Slices/Layout/_Head.cshtml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,19 @@
1111
<link rel="stylesheet preload" as="style" type="text/css" href="@Model.Static("styles.css")" crossorigin/>
1212
@if (Model.CanonicalBaseUrl is not null)
1313
{
14-
<link rel="canonical" href="@(new Uri(Model.CanonicalBaseUrl, Model.CurrentDocument.Url).ToString())">
14+
<link rel="canonical" href="@Model.CanonicalUrl" />
1515
}
1616
<meta name="viewport" content="width=device-width, initial-scale=1.0">
1717
@await RenderPartialAsync(_Favicon.Create())
1818
<meta name="robots" content="@(Model.AllowIndexing ? "index, follow" : "noindex, nofollow")">
1919
<meta name="htmx-config" content='{"selfRequestsOnly": true}'>
2020
<meta property="og:type" content="website"/>
21-
<meta property="og:title" content="Elastic Docs v3"/>
22-
<meta name="twitter:card" content="summary"/>
21+
<meta property="og:title" content="@Model.Title"/>
22+
<meta property="og:description" content="@Model.Description"/>
23+
<meta property="og:image" content="https://www.elastic.co/static-res/images/social_media_default.png"/>
24+
<meta property="og:image:alt" content="Elastic | The Search AI Company"/>
25+
@if (!string.IsNullOrEmpty(Model.CanonicalUrl))
26+
{
27+
<meta property="og:url" content="@Model.CanonicalUrl" />
28+
}
2329
</head>

src/Elastic.Markdown/Slices/_ViewModels.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public class LayoutViewModel
4747
public required string? GithubEditUrl { get; init; }
4848
public required bool AllowIndexing { get; init; }
4949
public required Uri? CanonicalBaseUrl { get; init; }
50+
51+
public string? CanonicalUrl => CanonicalBaseUrl is not null ? new Uri(CanonicalBaseUrl, CurrentDocument.Url).ToString() : null;
5052
public required FeatureFlags Features { get; init; }
5153

5254
private MarkdownFile[]? _parents;

0 commit comments

Comments
 (0)