0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Added site title and author to Mention entity

refs https://github.com/TryGhost/Team/issues/2435

We've made these fields optional, and we may need to extend this to other fields
too as we discover more about the data we're able to get access to.
This commit is contained in:
Fabien "egg" O'Carroll 2023-01-18 12:32:37 +07:00
parent f45bba21f6
commit 560d168169
3 changed files with 32 additions and 4 deletions

View file

@ -44,6 +44,18 @@ module.exports = class Mention {
return this.#sourceTitle;
}
/** @type {string} */
#sourceSiteTitle;
get sourceSiteTitle() {
return this.#sourceSiteTitle;
}
/** @type {string} */
#sourceAuthor;
get sourceAuthor() {
return this.#sourceAuthor;
}
/** @type {string} */
#sourceExcerpt;
get sourceExcerpt() {
@ -71,6 +83,8 @@ module.exports = class Mention {
payload: this.payload,
resourceId: this.resourceId,
sourceTitle: this.sourceTitle,
sourceSiteTitle: this.sourceSiteTitle,
sourceAuthor: this.sourceAuthor,
sourceExcerpt: this.sourceExcerpt,
sourceFavicon: this.sourceFavicon,
sourceFeaturedImage: this.sourceFeaturedImage
@ -86,6 +100,8 @@ module.exports = class Mention {
this.#payload = data.payload;
this.#resourceId = data.resourceId;
this.#sourceTitle = data.sourceTitle;
this.#sourceSiteTitle = data.sourceSiteTitle;
this.#sourceAuthor = data.sourceAuthor;
this.#sourceExcerpt = data.sourceExcerpt;
this.#sourceFavicon = data.sourceFavicon;
this.#sourceFeaturedImage = data.sourceFeaturedImage;
@ -151,6 +167,8 @@ module.exports = class Mention {
const sourceTitle = validateString(data.sourceTitle, 191, 'sourceTitle');
const sourceExcerpt = validateString(data.sourceExcerpt, 1000, 'sourceExcerpt');
const sourceSiteTitle = validateString(data.sourceSiteTitle, 191, 'sourceSiteTitle', false);
const sourceAuthor = validateString(data.sourceAuthor, 191, 'sourceAuthor', false);
let sourceFavicon = null;
if (data.sourceFavicon instanceof URL) {
@ -174,6 +192,8 @@ module.exports = class Mention {
payload,
resourceId,
sourceTitle,
sourceSiteTitle,
sourceAuthor,
sourceExcerpt,
sourceFavicon,
sourceFeaturedImage
@ -181,11 +201,15 @@ module.exports = class Mention {
}
};
function validateString(value, maxlength, name) {
function validateString(value, maxlength, name, required = true) {
if (!value) {
throw new ValidationError({
message: `Missing ${name} for Mention`
});
if (required) {
throw new ValidationError({
message: `Missing ${name} for Mention`
});
} else {
return null;
}
}
if (typeof value !== 'string') {

View file

@ -98,6 +98,8 @@ module.exports = class MentionsAPI {
payload: webmention.payload,
resourceId: null,
sourceTitle: 'Fake title',
sourceSiteTitle: 'Awesome Site',
sourceAuthor: 'James Bond',
sourceExcerpt: 'Wow, what an awesome article, blah blah blah',
sourceFavicon: null,
sourceFeaturedImage: null

View file

@ -22,6 +22,8 @@ describe('Mention', function () {
'payload',
'resourceId',
'sourceTitle',
'sourceSiteTitle',
'sourceAuthor',
'sourceExcerpt',
'sourceFavicon',
'sourceFeaturedImage'