mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Merge pull request #6823 from AileenCGN/structured-data-fix
Prevents sameAs property to be filled with `null`
This commit is contained in:
commit
59e5e10e85
2 changed files with 31 additions and 17 deletions
|
@ -15,6 +15,34 @@ function trimSchema(schema) {
|
||||||
return schemaObject;
|
return schemaObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function trimSameAs(data, context) {
|
||||||
|
var sameAs = [];
|
||||||
|
|
||||||
|
if (context === 'post') {
|
||||||
|
if (data.post.author.website) {
|
||||||
|
sameAs.push(data.post.author.website);
|
||||||
|
}
|
||||||
|
if (data.post.author.facebook) {
|
||||||
|
sameAs.push(data.post.author.facebook);
|
||||||
|
}
|
||||||
|
if (data.post.author.twitter) {
|
||||||
|
sameAs.push(data.post.author.twitter);
|
||||||
|
}
|
||||||
|
} else if (context === 'author') {
|
||||||
|
if (data.author.website) {
|
||||||
|
sameAs.push(data.author.website);
|
||||||
|
}
|
||||||
|
if (data.author.facebook) {
|
||||||
|
sameAs.push(data.author.facebook);
|
||||||
|
}
|
||||||
|
if (data.author.twitter) {
|
||||||
|
sameAs.push(data.author.twitter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sameAs;
|
||||||
|
}
|
||||||
|
|
||||||
function getPostSchema(metaData, data) {
|
function getPostSchema(metaData, data) {
|
||||||
var description = metaData.metaDescription ? escapeExpression(metaData.metaDescription) :
|
var description = metaData.metaDescription ? escapeExpression(metaData.metaDescription) :
|
||||||
(metaData.excerpt ? escapeExpression(metaData.excerpt) : null),
|
(metaData.excerpt ? escapeExpression(metaData.excerpt) : null),
|
||||||
|
@ -29,11 +57,7 @@ function getPostSchema(metaData, data) {
|
||||||
name: escapeExpression(data.post.author.name),
|
name: escapeExpression(data.post.author.name),
|
||||||
image: metaData.authorImage,
|
image: metaData.authorImage,
|
||||||
url: metaData.authorUrl,
|
url: metaData.authorUrl,
|
||||||
sameAs: [
|
sameAs: trimSameAs(data, 'post'),
|
||||||
data.post.author.website || null,
|
|
||||||
data.post.author.facebook || null,
|
|
||||||
data.post.author.twitter || null
|
|
||||||
],
|
|
||||||
description: data.post.author.bio ?
|
description: data.post.author.bio ?
|
||||||
escapeExpression(data.post.author.bio) :
|
escapeExpression(data.post.author.bio) :
|
||||||
null
|
null
|
||||||
|
@ -85,11 +109,7 @@ function getAuthorSchema(metaData, data) {
|
||||||
var schema = {
|
var schema = {
|
||||||
'@context': 'http://schema.org',
|
'@context': 'http://schema.org',
|
||||||
'@type': 'Person',
|
'@type': 'Person',
|
||||||
sameAs: [
|
sameAs: trimSameAs(data, 'author'),
|
||||||
data.author.website || null,
|
|
||||||
data.author.facebook || null,
|
|
||||||
data.author.twitter || null
|
|
||||||
],
|
|
||||||
publisher: escapeExpression(metaData.blog.title),
|
publisher: escapeExpression(metaData.blog.title),
|
||||||
name: escapeExpression(data.author.name),
|
name: escapeExpression(data.author.name),
|
||||||
url: metaData.authorUrl,
|
url: metaData.authorUrl,
|
||||||
|
|
|
@ -93,11 +93,7 @@ describe('getSchema', function () {
|
||||||
author: {
|
author: {
|
||||||
'@type': 'Person',
|
'@type': 'Person',
|
||||||
name: 'Post Author',
|
name: 'Post Author',
|
||||||
sameAs: [
|
sameAs: [],
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null
|
|
||||||
],
|
|
||||||
url: 'http://mysite.com/author/me/'
|
url: 'http://mysite.com/author/me/'
|
||||||
},
|
},
|
||||||
dateModified: '2016-01-21T22:13:05.412Z',
|
dateModified: '2016-01-21T22:13:05.412Z',
|
||||||
|
@ -170,7 +166,6 @@ describe('getSchema', function () {
|
||||||
author: {
|
author: {
|
||||||
name: 'Author Name',
|
name: 'Author Name',
|
||||||
website: 'http://myblogsite.com/',
|
website: 'http://myblogsite.com/',
|
||||||
facebook: 'https://www.facebook.com/testuser',
|
|
||||||
twitter: 'https://twitter.com/testuser'
|
twitter: 'https://twitter.com/testuser'
|
||||||
}
|
}
|
||||||
}, schema = getSchema(metadata, data);
|
}, schema = getSchema(metadata, data);
|
||||||
|
@ -183,7 +178,6 @@ describe('getSchema', function () {
|
||||||
publisher: 'Blog Title',
|
publisher: 'Blog Title',
|
||||||
sameAs: [
|
sameAs: [
|
||||||
'http://myblogsite.com/',
|
'http://myblogsite.com/',
|
||||||
'https://www.facebook.com/testuser',
|
|
||||||
'https://twitter.com/testuser'
|
'https://twitter.com/testuser'
|
||||||
],
|
],
|
||||||
url: 'http://mysite.com/author/me/'
|
url: 'http://mysite.com/author/me/'
|
||||||
|
|
Loading…
Add table
Reference in a new issue