mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-23 22:11:09 +03:00
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.
This commit is contained in:
parent
4215786bf1
commit
111c5742c9
@ -1,16 +1,20 @@
|
||||
const oembedService = require('../oembed');
|
||||
|
||||
module.exports = class WebmentionMetadata {
|
||||
/**
|
||||
* @param {URL} url
|
||||
* @returns {Promise<import('./MentionsAPI').WebmentionMetadata>}
|
||||
* @returns {Promise<import('@tryghost/webmentions/lib/MentionsAPI').WebmentionMetadata>}
|
||||
*/
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
@ -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'
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user