Added Open Graph to Category Pages

This commit is contained in:
Mia Rose Winter 2024-09-18 13:49:29 +02:00
parent f5949b1bca
commit f61188784d
Signed by: miawinter
GPG key ID: 4B6F6A83178F595E
2 changed files with 19 additions and 9 deletions

View file

@ -1,4 +1,5 @@
@using Microsoft.Extensions.Options @using System.Net
@using Microsoft.Extensions.Options
@using Wave.Data @using Wave.Data
@using Wave.Utilities @using Wave.Utilities
@ -53,6 +54,20 @@
<link rel="alternate" type="application/rss+xml" title="RSS Feed on @Customizations.Value.AppName | User @user.FullName" href="@Navigation.ToAbsoluteUri("/rss/rss.xml?author=@user.Id")"> <link rel="alternate" type="application/rss+xml" title="RSS Feed on @Customizations.Value.AppName | User @user.FullName" href="@Navigation.ToAbsoluteUri("/rss/rss.xml?author=@user.Id")">
<link rel="alternate" type="application/atom+xml" title="Atom RSS Feed on @Customizations.Value.AppName | User @user.FullName" href="@Navigation.ToAbsoluteUri("/rss/atom.xml?author=@user.Id")"> <link rel="alternate" type="application/atom+xml" title="Atom RSS Feed on @Customizations.Value.AppName | User @user.FullName" href="@Navigation.ToAbsoluteUri("/rss/atom.xml?author=@user.Id")">
} }
} else if (Subject is Category category) {
<meta property="og:title" content="@Localizer!["Title"] - @category.Name">
<meta property="og:description" content="Articles in the @category.Name Category on @Customizations.Value.AppName">
<meta property="og:type" content="website" />
@if (!string.IsNullOrWhiteSpace(Customizations.Value.LogoLink)) {
<meta property="og:image" content="@Customizations.Value.LogoLink">
} else {
<meta property="og:image" content="@Navigation.ToAbsoluteUri("/img/logo.png")">
}
@if (Features.Value.Rss) {
<link rel="alternate" type="application/rss+xml" title="RSS Feed on @Customizations.Value.AppName | @category.Name" href="@Navigation.ToAbsoluteUri("/rss/rss.xml?category=" + WebUtility.UrlEncode(category.Name))">
<link rel="alternate" type="application/atom+xml" title="Atom RSS Feed on @Customizations.Value.AppName | @category.Name" href="@Navigation.ToAbsoluteUri("/rss/atom.xml?category=" + WebUtility.UrlEncode(category.Name))">
}
} }
@code { @code {

View file

@ -2,19 +2,14 @@
@using Microsoft.EntityFrameworkCore @using Microsoft.EntityFrameworkCore
@using Wave.Data @using Wave.Data
@using System.Net @using System.Net
@using Microsoft.Extensions.Options
@inject IDbContextFactory<ApplicationDbContext> ContextFactory @inject IDbContextFactory<ApplicationDbContext> ContextFactory
@inject IOptions<Customization> Customizations
@inject IOptions<Features> Features
@inject IStringLocalizer<CategoryView> Localizer @inject IStringLocalizer<CategoryView> Localizer
<HeadContent> <HeadContent>
@if (Features.Value.Rss && Category is not null) { @if (Category is not null) {
<link rel="alternate" type="application/rss+xml" title="RSS Feed on @Customizations.Value.AppName | @Category.Name" href="/rss/rss.xml?category=@WebUtility.UrlEncode(Category.Name)"> <OpenGraph Subject="Category" Localizer="Localizer" />
<link rel="alternate" type="application/atom+xml" title="Atom RSS Feed on @Customizations.Value.AppName | @Category.Name" href="/rss/atom.xml?category=@WebUtility.UrlEncode(Category.Name)"> } else {
}
@if (Category is null) {
<meta name="robots" content="noindex"> <meta name="robots" content="noindex">
} }
</HeadContent> </HeadContent>