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
This commit is contained in:
Nazar Gargol 2019-06-06 17:01:03 +02:00
parent bdf1383b30
commit f5544e7831
8 changed files with 24 additions and 59 deletions

View File

@ -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));
}
}

View File

@ -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,

View File

@ -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')

View File

@ -1,5 +0,0 @@
module.exports = {
get urls() {
return require('./urls');
}
};

View File

@ -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(/^\//, '');
};

View File

@ -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');
});
});
});

View File

@ -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",

View File

@ -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"