-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
149 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using Kentico.Kontent.Delivery.Abstractions; | ||
using Kentico.Kontent.Statiq.Memoirs.Models; | ||
using System.Linq; | ||
|
||
namespace MemoirsTheme.Models | ||
{ | ||
public class SocialSharingMetadata | ||
{ | ||
public SocialSharingMetadata(IPageMetadata site, IPageMetadata page) | ||
{ | ||
Title = page.MetadataOgTitle.Cascade(page.MetadataMetaTitle).Cascade(page.Title); | ||
Url = page.Url; | ||
TwitterCard = page.MetadataTwitterCard.FirstOrDefault()?.Codename ?? "summary_large_image"; | ||
Description = page.MetadataOgDescription | ||
.Cascade(page.MetadataMetaDescription); | ||
Image = page.MetadataOgImage.FirstOrDefault() ?? site?.MetadataOgImage.FirstOrDefault(); | ||
TwitterSite = page.MetadataTwitterSite | ||
.Cascade(site?.MetadataTwitterSite); | ||
TwitterCreator = page.MetadataTwitterCreator | ||
.Cascade(site?.MetadataTwitterCreator); | ||
TwitterImage = page.MetadataTwitterImage.FirstOrDefault() ?? Image; | ||
} | ||
|
||
public string Url { get; } | ||
public string Title { get; } | ||
public string Description { get; } | ||
public IAsset Image { get; } | ||
public IAsset TwitterImage { get; } | ||
public string TwitterCreator { get; } | ||
public string TwitterSite { get; } | ||
public string TwitterCard { get; set; } | ||
} | ||
|
||
public static class MetadataHelpers | ||
{ | ||
public static string Cascade(this string preferred, string fallback) | ||
{ | ||
return string.IsNullOrWhiteSpace(preferred) ? fallback : preferred; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Kentico.Kontent.Delivery.Abstractions; | ||
using Kentico.Kontent.Delivery.Urls.QueryParameters; | ||
using Kontent.Statiq; | ||
using Statiq.Common; | ||
using Statiq.Core; | ||
|
||
namespace MemoirsTheme.Pipelines | ||
{ | ||
public class Seo : Pipeline | ||
{ | ||
public Seo(IDeliveryClient deliveryClient) | ||
{ | ||
InputModules = new ModuleList | ||
{ | ||
new Kontent<Kentico.Kontent.Statiq.Memoirs.Models.Home>(deliveryClient) | ||
.WithQuery(new LimitParameter(1), new DepthParameter(1)) | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
@model MemoirsTheme.Models.SocialSharingMetadata | ||
<meta property="og:type" content="website" /> | ||
<meta property="og:url" content="@Model.Url"> | ||
<meta property="og:title" content="@Model.Title"> | ||
<meta property="og:description" content="@Model.Description"> | ||
<meta name="twitter:card" content="@Model.TwitterCard"> | ||
@if (!string.IsNullOrWhiteSpace(@Model.TwitterCreator)) | ||
{ | ||
<meta name="twitter:site" content="@Model.TwitterSite"/> | ||
} | ||
@if (!string.IsNullOrWhiteSpace(@Model.TwitterCreator)) | ||
{ | ||
<meta name="twitter:creator" content="@Model.TwitterCreator" /> | ||
} | ||
|
||
@if (Model.Image != null) | ||
{ | ||
// https://developer.twitter.com/en/docs/tweets/optimize-with-cards/overview/abouts-cards | ||
// summary_large_image aspect 2:1, min 300x157 max 4096x4096 | ||
// summary aspect 1:1, min 144x144 max maximum of 4096x4096 pixels | ||
var width = 800; | ||
var height = 800; | ||
|
||
<meta property="og:image" content="@Model.Image.Url?w=@width&h=@height&fit=crop"> | ||
<meta property="og:image:alt" content="@Model.Image.Description" /> | ||
<meta property="og:image:width" content="@width" /> | ||
<meta property="og:image:height" content="@height" /> | ||
<meta property="og:image:type" content="@Model.Image.Type" /> | ||
} | ||
|
||
@if (Model.TwitterImage != null) | ||
{ | ||
// https://ogp.me/ | ||
// summary_large_image aspect 2:1, min 300x157 max 4096x4096 | ||
// summary aspect 1:1, min 144x144 max maximum of 4096x4096 pixels | ||
var (height, width) = Model.TwitterCard switch | ||
{ | ||
"summary_large_image" => (height: 500, width: 1000), | ||
_ => (height: 500, width: 500) | ||
}; | ||
|
||
<meta name="twitter:image" content="@Model.TwitterImage.Url?w=@width&h=@height&fit=crop"> | ||
<meta name="twitter:image:alt" content="@Model.TwitterImage.Description" /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters