diff --git a/core/server/data/meta/schema.js b/core/server/data/meta/schema.js index a4ad4169fbd..ad4eee23956 100644 --- a/core/server/data/meta/schema.js +++ b/core/server/data/meta/schema.js @@ -1,5 +1,6 @@ var config = require('../../config'), hbs = require('express-hbs'), + socialUrls = require('../../utils/social-urls'), escapeExpression = hbs.handlebars.Utils.escapeExpression, _ = require('lodash'); @@ -23,20 +24,20 @@ function trimSameAs(data, context) { sameAs.push(data.post.author.website); } if (data.post.author.facebook) { - sameAs.push(data.post.author.facebook); + sameAs.push(socialUrls.facebookUrl(data.post.author.facebook)); } if (data.post.author.twitter) { - sameAs.push(data.post.author.twitter); + sameAs.push(socialUrls.twitterUrl(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); + sameAs.push(socialUrls.facebookUrl(data.author.facebook)); } if (data.author.twitter) { - sameAs.push(data.author.twitter); + sameAs.push(socialUrls.twitterUrl(data.author.twitter)); } } diff --git a/core/server/data/meta/structured_data.js b/core/server/data/meta/structured_data.js index f0c9db6fd9d..13cfe131237 100644 --- a/core/server/data/meta/structured_data.js +++ b/core/server/data/meta/structured_data.js @@ -1,16 +1,13 @@ +var socialUrls = require('../../utils/social-urls'); + function getStructuredData(metaData) { var structuredData, - card = 'summary', - twitterUser; + card = 'summary'; if (metaData.coverImage) { card = 'summary_large_image'; } - if (metaData.creatorTwitter) { - twitterUser = '@' + metaData.creatorTwitter.match(/(?:https:\/\/)(?:twitter\.com)\/(?:#!\/)?@?([^\/]*)/)[1]; - } - structuredData = { 'og:site_name': metaData.blog.title, 'og:type': metaData.ogType, @@ -21,8 +18,8 @@ function getStructuredData(metaData) { 'article:published_time': metaData.publishedDate, 'article:modified_time': metaData.modifiedDate, 'article:tag': metaData.keywords, - 'article:publisher': metaData.blog.facebook || undefined, - 'article:author': metaData.authorFacebook || undefined, + 'article:publisher': metaData.blog.facebook ? socialUrls.facebookUrl(metaData.blog.facebook) : undefined, + 'article:author': metaData.authorFacebook ? socialUrls.facebookUrl(metaData.authorFacebook) : undefined, 'twitter:card': card, 'twitter:title': metaData.metaTitle, 'twitter:description': metaData.metaDescription || metaData.excerpt, @@ -33,7 +30,7 @@ function getStructuredData(metaData) { 'twitter:label2': metaData.keywords ? 'Filed under' : undefined, 'twitter:data2': metaData.keywords ? metaData.keywords.join(', ') : undefined, 'twitter:site': metaData.blog.twitter || undefined, - 'twitter:creator': twitterUser || undefined + 'twitter:creator': metaData.creatorTwitter || undefined }; // return structured data removing null or undefined keys diff --git a/core/test/unit/metadata/schema_spec.js b/core/test/unit/metadata/schema_spec.js index 2e9299e8dd7..932c1bda3dd 100644 --- a/core/test/unit/metadata/schema_spec.js +++ b/core/test/unit/metadata/schema_spec.js @@ -10,7 +10,7 @@ describe('getSchema', function () { logo: 'http://mysite.com/author/image/url/logo.jpg' }, authorImage: 'http://mysite.com/author/image/url/me.jpg', - authorFacebook: 'https://facebook.com/testuser', + authorFacebook: 'testuser', creatorTwitter: '@testuser', authorUrl: 'http://mysite.com/author/me/', metaTitle: 'Post Title', @@ -27,8 +27,8 @@ describe('getSchema', function () { name: 'Post Author', website: 'http://myblogsite.com/', bio: 'My author bio.', - facebook: 'https://www.facebook.com/testuser', - twitter: 'https://twitter.com/testuser' + facebook: 'testuser', + twitter: '@testuser' } } }, schema = getSchema(metadata, data); @@ -175,7 +175,7 @@ describe('getSchema', function () { author: { name: 'Author Name', website: 'http://myblogsite.com/', - twitter: 'https://twitter.com/testuser' + twitter: '@testuser' } }, schema = getSchema(metadata, data); diff --git a/core/test/unit/metadata/structured_data_spec.js b/core/test/unit/metadata/structured_data_spec.js index 13b761cfe5a..f6278b914f6 100644 --- a/core/test/unit/metadata/structured_data_spec.js +++ b/core/test/unit/metadata/structured_data_spec.js @@ -7,7 +7,7 @@ describe('getStructuredData', function () { var metadata = { blog: { title: 'Blog Title', - facebook: 'https://www.facebook.com/testuser', + facebook: 'testuser', twitter: '@testuser' }, authorName: 'Test User', @@ -17,8 +17,8 @@ describe('getStructuredData', function () { publishedDate: '2015-12-25T05:35:01.234Z', modifiedDate: '2016-01-21T22:13:05.412Z', coverImage: 'http://mysite.com/content/image/mypostcoverimage.jpg', - authorFacebook: 'https://www.facebook.com/testpage', - creatorTwitter: 'https://twitter.com/twitterpage', + authorFacebook: 'testpage', + creatorTwitter: '@twitterpage', keywords: ['one', 'two', 'tag'], metaDescription: 'Post meta description' }, structuredData = getStructuredData(metadata); diff --git a/core/test/unit/server_helpers/ghost_head_spec.js b/core/test/unit/server_helpers/ghost_head_spec.js index a491b6688aa..e0116f6946a 100644 --- a/core/test/unit/server_helpers/ghost_head_spec.js +++ b/core/test/unit/server_helpers/ghost_head_spec.js @@ -124,8 +124,8 @@ describe('{{ghost_head}} helper', function () { slug: 'Author', image: '/content/images/test-author-image.png', website: 'http://authorwebsite.com', - facebook: 'https://www.facebook.com/testuser', - twitter: 'https://twitter.com/testuser', + facebook: 'testuser', + twitter: '@testuser', bio: 'Author bio' } }; @@ -301,8 +301,8 @@ describe('{{ghost_head}} helper', function () { image: '/content/images/test-author-image.png', cover: '/content/images/author-cover-image.png', website: 'http://authorwebsite.com', - facebook: 'https://www.facebook.com/testuser', - twitter: 'https://twitter.com/testuser' + facebook: 'testuser', + twitter: '@testuser' }, authorBk = _.cloneDeep(author); helpers.ghost_head.call( @@ -393,8 +393,8 @@ describe('{{ghost_head}} helper', function () { image: '/content/images/test-author-image.png', website: 'http://authorwebsite.com', bio: 'Author bio', - facebook: 'https://www.facebook.com/testuser', - twitter: 'https://twitter.com/testuser' + facebook: 'testuser', + twitter: '@testuser' } }, postBk = _.cloneDeep(post); @@ -470,8 +470,8 @@ describe('{{ghost_head}} helper', function () { slug: 'Author', image: '/content/images/test-author-image.png', website: 'http://authorwebsite.com', - facebook: 'https://www.facebook.com/testuser', - twitter: 'https://twitter.com/testuser' + facebook: 'testuser', + twitter: '@testuser' } }; @@ -546,8 +546,8 @@ describe('{{ghost_head}} helper', function () { slug: 'Author', image: '/content/images/test-author-image.png', website: 'http://authorwebsite.com', - facebook: 'https://www.facebook.com/testuser', - twitter: 'https://twitter.com/testuser' + facebook: 'testuser', + twitter: '@testuser' } }; @@ -618,8 +618,8 @@ describe('{{ghost_head}} helper', function () { slug: 'Author', image: null, website: 'http://authorwebsite.com', - facebook: 'https://www.facebook.com/testuser', - twitter: 'https://twitter.com/testuser' + facebook: 'testuser', + twitter: '@testuser' } }; @@ -833,8 +833,8 @@ describe('{{ghost_head}} helper', function () { slug: 'Author', image: 'content/images/test-author-image.png', website: 'http://authorwebsite.com', - facebook: 'https://www.facebook.com/testuser', - twitter: 'https://twitter.com/testuser' + facebook: 'testuser', + twitter: '@testuser' } };