From 111c5742c9abdc531e570604b921d61f9fdf8c1a Mon Sep 17 00:00:00 2001 From: "Fabien \"egg\" O'Carroll" Date: Thu, 19 Jan 2023 19:14:07 +0700 Subject: [PATCH] Implemented WebmentionMetadata using the oembed service https://github.com/TryGhost/Team/issues/2458 This is an initial pass at pulling metadata from webmention sources, we've also updated the fake data to pull from some real-world sites which implement webmentions. We've reused the oembed service here, long term it would be nice to pull the metadata parsing/pulling part out, so that we can have more generic error messages. --- .../services/mentions/WebmentionMetadata.js | 22 +++++++++------- .../core/server/services/mentions/service.js | 26 +++++++++++++++---- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/ghost/core/core/server/services/mentions/WebmentionMetadata.js b/ghost/core/core/server/services/mentions/WebmentionMetadata.js index 14f6ba8bec..2668a022e0 100644 --- a/ghost/core/core/server/services/mentions/WebmentionMetadata.js +++ b/ghost/core/core/server/services/mentions/WebmentionMetadata.js @@ -1,16 +1,20 @@ +const oembedService = require('../oembed'); + module.exports = class WebmentionMetadata { /** * @param {URL} url - * @returns {Promise} + * @returns {Promise} */ - async fetch() { - return { - siteTitle: 'Clickbait News', - title: 'This egg breakfast will make you cry', - excerpt: 'How many times have you woken up and almost cancelled your church plans? Well this breakfast is about to change everything, a hearty, faith restoring egg dish that will get your tastebuds in a twist.', - author: 'Dr Egg Man', - image: new URL('https://unsplash.com/photos/QAND9huzD04'), - favicon: new URL('https://ghost.org/favicon.ico') + async fetch(url) { + const data = await oembedService.fetchOembedDataFromUrl(url.href, 'bookmark'); + const result = { + siteTitle: data.metadata.publisher, + title: data.metadata.title, + excerpt: data.metadata.description, + author: data.metadata.author, + image: new URL(data.metadata.thumbnail), + favicon: new URL(data.metadata.icon) }; + return result; } }; diff --git a/ghost/core/core/server/services/mentions/service.js b/ghost/core/core/server/services/mentions/service.js index 3096942629..024e7481f6 100644 --- a/ghost/core/core/server/services/mentions/service.js +++ b/ghost/core/core/server/services/mentions/service.js @@ -28,14 +28,30 @@ module.exports = { } }); - api.processWebmention({ - source: new URL('https://egg.com/post'), - target: new URL('https://ronald.com/pizza'), - payload: { + this.controller.init({api}); + + this.controller.receive({ + data: { + source: 'https://brid.gy/repost/twitter/KiaKamgar/1615735511137624064/1615738476875366401', + target: 'https://ronald.com/pizza/', extra: 'data' } }); - this.controller.init({api}); + this.controller.receive({ + data: { + source: 'https://slrpnk.net/post/222314', + target: 'https://ronald.com/thing/', + extra: 'data' + } + }); + + this.controller.receive({ + data: { + source: 'https://lobste.rs/s/eq4f9d', + target: 'https://ronald.com/whatever/', + extra: 'data' + } + }); } };