mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-04-15 03:01:37 -05:00
Updated page metadata to use author image over cover image (#17689)
- the schema.org data fo an author should primarily use the authors image as the image item instead of the cover image. - otherwise the schema.org metadata will be invalid, since the image item is missing when no cover image has been uploaded.
This commit is contained in:
parent
4e2710ada2
commit
082a67c7f6
3 changed files with 123 additions and 2 deletions
|
@ -152,7 +152,7 @@ function getAuthorSchema(metaData, data) {
|
|||
sameAs: trimSameAs(data, 'author'),
|
||||
name: escapeExpression(data.author.name),
|
||||
url: metaData.authorUrl,
|
||||
image: schemaImageObject(metaData.coverImage),
|
||||
image: schemaImageObject(metaData.authorImage) || schemaImageObject(metaData.coverImage),
|
||||
mainEntityOfPage: metaData.authorUrl,
|
||||
description: metaData.metaDescription ?
|
||||
escapeExpression(metaData.metaDescription) :
|
||||
|
|
|
@ -104,6 +104,18 @@ describe('{{ghost_head}} helper', function () {
|
|||
updated_at: new Date(0)
|
||||
}));
|
||||
|
||||
// User without profile image but with cover image
|
||||
users.push(createUser({
|
||||
name: 'Author name',
|
||||
slug: 'AuthorName2',
|
||||
bio: 'Author bio',
|
||||
cover_image: '/content/images/author-cover-image.png',
|
||||
website: 'http://authorwebsite.com',
|
||||
facebook: 'testuser',
|
||||
twitter: '@testuser',
|
||||
updated_at: new Date(0)
|
||||
}));
|
||||
|
||||
/** AUTHORS - related to posts */
|
||||
authors.push(createUser({// Author 0
|
||||
profile_image: '/content/images/test-author-image.png',
|
||||
|
@ -714,7 +726,7 @@ describe('{{ghost_head}} helper', function () {
|
|||
|
||||
it('returns structured data and schema on first author page with cover image', async function () {
|
||||
await testGhostHead(testUtils.createHbsResponse({
|
||||
renderObject: {author: users[0]},
|
||||
renderObject: {author: users[2]},
|
||||
locals: {
|
||||
// @TODO: WHY?
|
||||
relativeUrl: '/author/authorname/',
|
||||
|
|
|
@ -576,6 +576,115 @@ describe('getSchema', function () {
|
|||
'@context': 'https://schema.org',
|
||||
'@type': 'Person',
|
||||
description: 'This is the author description!',
|
||||
image: {
|
||||
'@type': 'ImageObject',
|
||||
height: 500,
|
||||
url: 'http://mysite.com/author/image/url/me.jpg',
|
||||
width: 500
|
||||
},
|
||||
mainEntityOfPage: 'http://mysite.com/author/me/',
|
||||
name: 'Author Name',
|
||||
sameAs: [
|
||||
'http://myblogsite.com/?user=bambedibu&a=<script>alert("bambedibu")</script>',
|
||||
'https://twitter.com/testuser'
|
||||
],
|
||||
url: 'http://mysite.com/author/me/'
|
||||
});
|
||||
});
|
||||
|
||||
it('should return author schema if context starts with author and prefer the author profile image if also a cover image is given', function () {
|
||||
const metadata = {
|
||||
site: {
|
||||
title: 'Site Title',
|
||||
url: 'http://mysite.com'
|
||||
},
|
||||
authorImage: {
|
||||
url: 'http://mysite.com/author/image/url/me.jpg',
|
||||
dimensions: {
|
||||
width: 500,
|
||||
height: 500
|
||||
}
|
||||
},
|
||||
coverImage: {
|
||||
url: 'http://mysite.com/author/cover/url/me.jpg',
|
||||
dimensions: {
|
||||
width: 1024,
|
||||
height: 500
|
||||
}
|
||||
},
|
||||
authorUrl: 'http://mysite.com/author/me/',
|
||||
metaDescription: 'This is the author description!'
|
||||
};
|
||||
|
||||
const data = {
|
||||
context: ['author'],
|
||||
author: {
|
||||
name: 'Author Name',
|
||||
website: 'http://myblogsite.com/?user=bambedibu&a=<script>alert("bambedibu")</script>',
|
||||
twitter: '@testuser'
|
||||
}
|
||||
};
|
||||
|
||||
const schema = getSchema(metadata, data);
|
||||
|
||||
should.deepEqual(schema, {
|
||||
'@context': 'https://schema.org',
|
||||
'@type': 'Person',
|
||||
description: 'This is the author description!',
|
||||
image: {
|
||||
'@type': 'ImageObject',
|
||||
height: 500,
|
||||
url: 'http://mysite.com/author/image/url/me.jpg',
|
||||
width: 500
|
||||
},
|
||||
mainEntityOfPage: 'http://mysite.com/author/me/',
|
||||
name: 'Author Name',
|
||||
sameAs: [
|
||||
'http://myblogsite.com/?user=bambedibu&a=<script>alert("bambedibu")</script>',
|
||||
'https://twitter.com/testuser'
|
||||
],
|
||||
url: 'http://mysite.com/author/me/'
|
||||
});
|
||||
});
|
||||
|
||||
it('should return author schema if context starts with author and fall back to the cover image if given', function () {
|
||||
const metadata = {
|
||||
site: {
|
||||
title: 'Site Title',
|
||||
url: 'http://mysite.com'
|
||||
},
|
||||
coverImage: {
|
||||
url: 'http://mysite.com/author/cover/url/me.jpg',
|
||||
dimensions: {
|
||||
width: 1024,
|
||||
height: 500
|
||||
}
|
||||
},
|
||||
authorUrl: 'http://mysite.com/author/me/',
|
||||
metaDescription: 'This is the author description!'
|
||||
};
|
||||
|
||||
const data = {
|
||||
context: ['author'],
|
||||
author: {
|
||||
name: 'Author Name',
|
||||
website: 'http://myblogsite.com/?user=bambedibu&a=<script>alert("bambedibu")</script>',
|
||||
twitter: '@testuser'
|
||||
}
|
||||
};
|
||||
|
||||
const schema = getSchema(metadata, data);
|
||||
|
||||
should.deepEqual(schema, {
|
||||
'@context': 'https://schema.org',
|
||||
'@type': 'Person',
|
||||
description: 'This is the author description!',
|
||||
image: {
|
||||
'@type': 'ImageObject',
|
||||
height: 500,
|
||||
url: 'http://mysite.com/author/cover/url/me.jpg',
|
||||
width: 1024
|
||||
},
|
||||
mainEntityOfPage: 'http://mysite.com/author/me/',
|
||||
name: 'Author Name',
|
||||
sameAs: [
|
||||
|
|
Loading…
Add table
Reference in a new issue