From f5544e7831c931653f096d62a2b882d80fe5d628 Mon Sep 17 00:00:00 2001 From: Nazar Gargol Date: Thu, 6 Jun 2019 17:01:03 +0200 Subject: [PATCH] Migrated to use @tryghost/social-urls package refs #10618 - /lib/social/urls was extracted into SDK to move more modules out of the core and reduce coupling of the theme layer --- core/server/data/meta/schema.js | 10 +++---- core/server/data/meta/structured_data.js | 6 ++-- core/server/helpers/proxy.js | 2 +- core/server/lib/social/index.js | 5 ---- core/server/lib/social/urls.js | 9 ------ core/test/unit/lib/social/urls_spec.js | 36 ------------------------ package.json | 1 + yarn.lock | 14 +++++++++ 8 files changed, 24 insertions(+), 59 deletions(-) delete mode 100644 core/server/lib/social/index.js delete mode 100644 core/server/lib/social/urls.js delete mode 100644 core/test/unit/lib/social/urls_spec.js diff --git a/core/server/data/meta/schema.js b/core/server/data/meta/schema.js index 9f13f278e0..2015af9c71 100644 --- a/core/server/data/meta/schema.js +++ b/core/server/data/meta/schema.js @@ -1,6 +1,6 @@ var config = require('../../config'), escapeExpression = require('../../services/themes/engine').escapeExpression, - social = require('../../lib/social'), + socialUrls = require('@tryghost/social-urls'), _ = require('lodash'); function schemaImageObject(metaDataVal) { @@ -43,20 +43,20 @@ function trimSameAs(data, context) { sameAs.push(escapeExpression(data[context].primary_author.website)); } if (data[context].primary_author.facebook) { - sameAs.push(social.urls.facebook(data[context].primary_author.facebook)); + sameAs.push(socialUrls.facebook(data[context].primary_author.facebook)); } if (data[context].primary_author.twitter) { - sameAs.push(social.urls.twitter(data[context].primary_author.twitter)); + sameAs.push(socialUrls.twitter(data[context].primary_author.twitter)); } } else if (context === 'author') { if (data.author.website) { sameAs.push(escapeExpression(data.author.website)); } if (data.author.facebook) { - sameAs.push(social.urls.facebook(data.author.facebook)); + sameAs.push(socialUrls.facebook(data.author.facebook)); } if (data.author.twitter) { - sameAs.push(social.urls.twitter(data.author.twitter)); + sameAs.push(socialUrls.twitter(data.author.twitter)); } } diff --git a/core/server/data/meta/structured_data.js b/core/server/data/meta/structured_data.js index 17ed025bfb..7f6e1da5ac 100644 --- a/core/server/data/meta/structured_data.js +++ b/core/server/data/meta/structured_data.js @@ -1,4 +1,4 @@ -var social = require('../../lib/social'); +var socialUrls = require('@tryghost/social-urls'); function getStructuredData(metaData) { var structuredData, @@ -21,8 +21,8 @@ function getStructuredData(metaData) { 'article:published_time': metaData.publishedDate, 'article:modified_time': metaData.modifiedDate, 'article:tag': metaData.keywords, - 'article:publisher': metaData.blog.facebook ? social.urls.facebook(metaData.blog.facebook) : undefined, - 'article:author': metaData.authorFacebook ? social.urls.facebook(metaData.authorFacebook) : undefined, + 'article:publisher': metaData.blog.facebook ? socialUrls.facebook(metaData.blog.facebook) : undefined, + 'article:author': metaData.authorFacebook ? socialUrls.facebook(metaData.authorFacebook) : undefined, 'twitter:card': card, 'twitter:title': metaData.twitterTitle || metaData.metaTitle, 'twitter:description': metaData.twitterDescription || metaData.excerpt || metaData.metaDescription, diff --git a/core/server/helpers/proxy.js b/core/server/helpers/proxy.js index cef6bf96ef..8c2b2969b5 100644 --- a/core/server/helpers/proxy.js +++ b/core/server/helpers/proxy.js @@ -58,7 +58,7 @@ module.exports = { templates: require('./template'), // Various utils, needs cleaning up / simplifying - socialUrls: require('../lib/social/urls'), + socialUrls: require('@tryghost/social-urls'), blogIcon: require('../lib/image/blog-icon'), urlService: require('../services/url'), localUtils: require('./utils') diff --git a/core/server/lib/social/index.js b/core/server/lib/social/index.js deleted file mode 100644 index e1e2c0ea2b..0000000000 --- a/core/server/lib/social/index.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - get urls() { - return require('./urls'); - } -}; diff --git a/core/server/lib/social/urls.js b/core/server/lib/social/urls.js deleted file mode 100644 index 5cb40f4845..0000000000 --- a/core/server/lib/social/urls.js +++ /dev/null @@ -1,9 +0,0 @@ -module.exports.twitter = function twitter(username) { - // Creates the canonical twitter URL without the '@' - return 'https://twitter.com/' + username.replace(/^@/, ''); -}; - -module.exports.facebook = function facebook(username) { - // Handles a starting slash, this shouldn't happen, but just in case - return 'https://www.facebook.com/' + username.replace(/^\//, ''); -}; diff --git a/core/test/unit/lib/social/urls_spec.js b/core/test/unit/lib/social/urls_spec.js deleted file mode 100644 index 88a7e0fe5a..0000000000 --- a/core/test/unit/lib/social/urls_spec.js +++ /dev/null @@ -1,36 +0,0 @@ -var should = require('should'), - social = require('../../../../server/lib/social'); - -describe('lib/social: urls', function () { - it('should have a twitter url function', function () { - should.exist(social.urls.twitter); - }); - - it('should have a facebook url function', function () { - should.exist(social.urls.facebook); - }); - - describe('twitter', function () { - it('should return a correct concatenated URL', function () { - social.urls.twitter('myusername').should.eql('https://twitter.com/myusername'); - }); - - it('should return a url without an @ sign if one is provided', function () { - social.urls.twitter('@myusername').should.eql('https://twitter.com/myusername'); - }); - }); - - describe('facebook', function () { - it('should return a correct concatenated URL', function () { - social.urls.facebook('myusername').should.eql('https://www.facebook.com/myusername'); - }); - - it('should return a correct concatenated URL for usernames with slashes', function () { - social.urls.facebook('page/xxx/123').should.eql('https://www.facebook.com/page/xxx/123'); - }); - - it('should return a correct concatenated URL for usernames which start with a slash', function () { - social.urls.facebook('/page/xxx/123').should.eql('https://www.facebook.com/page/xxx/123'); - }); - }); -}); diff --git a/package.json b/package.json index e5575443c5..7ac423274f 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "@tryghost/members-auth-pages": "0.2.1", "@tryghost/members-ssr": "0.1.5", "@tryghost/members-theme-bindings": "^0.1.0", + "@tryghost/social-urls": "0.1.0", "@tryghost/string": "^0.1.3", "ajv": "6.8.1", "amperize": "0.4.0", diff --git a/yarn.lock b/yarn.lock index 4f6680f8b5..a457f5511b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -236,6 +236,15 @@ chalk "^2.4.1" sywac "^1.2.1" +"@tryghost/social-urls@0.1.0": + version "0.1.0" + resolved "https://registry.yarnpkg.com/@tryghost/social-urls/-/social-urls-0.1.0.tgz#5e41d2108674e420d9e92d5fc6296e185838eadb" + integrity sha512-aBJvQmKDtEZ9nqOcl+jGOnmXndK1qjtIp1p3ExVS/XpzmRApvxBn5ImcIX1rZ8eiyOk0GU4DygerxpKKBE5ARw== + dependencies: + bluebird "3.5.5" + ghost-ignition "3.1.0" + lodash "4.17.11" + "@tryghost/string@^0.1.3": version "0.1.3" resolved "https://registry.yarnpkg.com/@tryghost/string/-/string-0.1.3.tgz#aad595f40f984570aff042b08f407e67dc47f692" @@ -728,6 +737,11 @@ bluebird@3.5.4, bluebird@^3.5.4: resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.4.tgz#d6cc661595de30d5b3af5fcedd3c0b3ef6ec5714" integrity sha512-FG+nFEZChJrbQ9tIccIfZJBz3J7mLrAhxakAbnrJWn8d7aKOC+LWifa0G+p4ZqKp4y13T7juYvdhq9NzKdsrjw== +bluebird@3.5.5: + version "3.5.5" + resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.5.tgz#a8d0afd73251effbbd5fe384a77d73003c17a71f" + integrity sha512-5am6HnnfN+urzt4yfg7IgTbotDjIT/u8AJpEt0sIU9FtXfVeezXAPKswrG+xKUCOYAINpSdgZVDU6QFh+cuH3w== + body-parser@1.18.3: version "1.18.3" resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.18.3.tgz#5b292198ffdd553b3a0f20ded0592b956955c8b4"