From 2fde12d7e1843260c66773ca89a6ac889791b6d3 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 8 Dec 2023 08:41:14 +0100 Subject: [PATCH] Fix profile page JSONLD --- server/core/lib/html/shared/actor-html.ts | 4 +++ server/core/lib/html/shared/tags-html.ts | 30 ++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/server/core/lib/html/shared/actor-html.ts b/server/core/lib/html/shared/actor-html.ts index 121b22afe..0a9056483 100644 --- a/server/core/lib/html/shared/actor-html.ts +++ b/server/core/lib/html/shared/actor-html.ts @@ -80,6 +80,10 @@ export class ActorHtml { ogType, twitterCard, schemaType, + jsonldProfile: { + createdAt: entity.createdAt, + updatedAt: entity.updatedAt + }, indexationPolicy: entity.Actor.isOwned() ? 'always' diff --git a/server/core/lib/html/shared/tags-html.ts b/server/core/lib/html/shared/tags-html.ts index 297888605..3df840fd9 100644 --- a/server/core/lib/html/shared/tags-html.ts +++ b/server/core/lib/html/shared/tags-html.ts @@ -11,10 +11,16 @@ type Tags = { url?: string - schemaType?: string ogType?: string twitterCard?: 'player' | 'summary' | 'summary_large_image' + schemaType?: string + + jsonldProfile?: { + createdAt: Date + updatedAt: Date + } + list?: { numberOfItems: number } @@ -195,6 +201,28 @@ export class TagsHtml { static generateSchemaTagsOptions (tags: Tags, context: HookContext) { if (!tags.schemaType) return + if (tags.schemaType === 'ProfilePage') { + if (!tags.jsonldProfile) throw new Error('Missing `jsonldProfile` with ProfilePage schema type') + + const profilePageSchema = { + '@context': 'http://schema.org', + '@type': tags.schemaType, + + 'dateCreated': tags.jsonldProfile.createdAt.toISOString(), + 'dateModified': tags.jsonldProfile.updatedAt.toISOString(), + + 'mainEntity': { + '@id': '#main-author', + '@type': 'Person', + 'name': tags.escapedTitle, + 'description': tags.escapedTruncatedDescription, + 'image': tags.image.url + } + } + + return Hooks.wrapObject(profilePageSchema, 'filter:html.client.json-ld.result', context) + } + const schema = { '@context': 'http://schema.org', '@type': tags.schemaType,