mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Moved social utility to lib/social
refs #9178 - not 100% sure about this, but i think it makes right now the most sense - we have already a url service and creating another lib/url is confusing at the moment - i'll copy the last utility `makeAbsoluteUrls` to the url service for now - see next commit for explanation (!)
This commit is contained in:
parent
b474fb0d16
commit
64626dedd1
9 changed files with 31 additions and 26 deletions
|
@ -1,6 +1,6 @@
|
|||
var config = require('../../config'),
|
||||
escapeExpression = require('../../services/themes/engine').escapeExpression,
|
||||
socialUrls = require('../../utils/social-urls'),
|
||||
social = require('../../lib/social'),
|
||||
_ = require('lodash');
|
||||
|
||||
function schemaImageObject(metaDataVal) {
|
||||
|
@ -43,20 +43,20 @@ function trimSameAs(data, context) {
|
|||
sameAs.push(escapeExpression(data.post.author.website));
|
||||
}
|
||||
if (data.post.author.facebook) {
|
||||
sameAs.push(socialUrls.facebookUrl(data.post.author.facebook));
|
||||
sameAs.push(social.urls.facebook(data.post.author.facebook));
|
||||
}
|
||||
if (data.post.author.twitter) {
|
||||
sameAs.push(socialUrls.twitterUrl(data.post.author.twitter));
|
||||
sameAs.push(social.urls.twitter(data.post.author.twitter));
|
||||
}
|
||||
} else if (context === 'author') {
|
||||
if (data.author.website) {
|
||||
sameAs.push(escapeExpression(data.author.website));
|
||||
}
|
||||
if (data.author.facebook) {
|
||||
sameAs.push(socialUrls.facebookUrl(data.author.facebook));
|
||||
sameAs.push(social.urls.facebook(data.author.facebook));
|
||||
}
|
||||
if (data.author.twitter) {
|
||||
sameAs.push(socialUrls.twitterUrl(data.author.twitter));
|
||||
sameAs.push(social.urls.twitter(data.author.twitter));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var socialUrls = require('../../utils/social-urls');
|
||||
var social = require('../../lib/social');
|
||||
|
||||
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 ? socialUrls.facebookUrl(metaData.blog.facebook) : undefined,
|
||||
'article:author': metaData.authorFacebook ? socialUrls.facebookUrl(metaData.authorFacebook) : undefined,
|
||||
'article:publisher': metaData.blog.facebook ? social.urls.facebook(metaData.blog.facebook) : undefined,
|
||||
'article:author': metaData.authorFacebook ? social.urls.facebook(metaData.authorFacebook) : undefined,
|
||||
'twitter:card': card,
|
||||
'twitter:title': metaData.twitterTitle || metaData.metaTitle,
|
||||
'twitter:description': metaData.twitterDescription || metaData.excerpt || metaData.metaDescription,
|
||||
|
|
|
@ -14,7 +14,7 @@ module.exports = function facebook_url(username, options) { // eslint-disable-li
|
|||
}
|
||||
|
||||
if (username) {
|
||||
return socialUrls.facebookUrl(username);
|
||||
return socialUrls.facebook(username);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
@ -62,7 +62,7 @@ module.exports = {
|
|||
templates: require('./template'),
|
||||
|
||||
// Various utils, needs cleaning up / simplifying
|
||||
socialUrls: require('../utils/social-urls'),
|
||||
socialUrls: require('../lib/social/urls'),
|
||||
blogIcon: require('../lib/image/blog-icon'),
|
||||
url: require('../services/url').utils,
|
||||
localUtils: require('./utils')
|
||||
|
|
|
@ -14,7 +14,7 @@ module.exports = function twitter_url(username, options) { // eslint-disable-lin
|
|||
}
|
||||
|
||||
if (username) {
|
||||
return socialUrls.twitterUrl(username);
|
||||
return socialUrls.twitter(username);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
7
core/server/lib/social/index.js
Normal file
7
core/server/lib/social/index.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
get urls() {
|
||||
return require('./urls');
|
||||
}
|
||||
};
|
|
@ -1,9 +1,9 @@
|
|||
module.exports.twitterUrl = function twitterUrl(username) {
|
||||
module.exports.twitter = function twitter(username) {
|
||||
// Creates the canonical twitter URL without the '@'
|
||||
return 'https://twitter.com/' + username.replace(/^@/, '');
|
||||
};
|
||||
|
||||
module.exports.facebookUrl = function facebookUrl(username) {
|
||||
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(/^\//, '');
|
||||
};
|
|
@ -1,38 +1,36 @@
|
|||
var should = require('should'),
|
||||
social = require('../../../../server/lib/social');
|
||||
|
||||
// Stuff we are testing
|
||||
socialUrls = require('../../../server/utils/social-urls');
|
||||
|
||||
describe('Social Urls', function () {
|
||||
describe('lib/social: urls', function () {
|
||||
it('should have a twitter url function', function () {
|
||||
should.exist(socialUrls.twitterUrl);
|
||||
should.exist(social.urls.twitter);
|
||||
});
|
||||
|
||||
it('should have a facebook url function', function () {
|
||||
should.exist(socialUrls.facebookUrl);
|
||||
should.exist(social.urls.facebook);
|
||||
});
|
||||
|
||||
describe('twitter', function () {
|
||||
it('should return a correct concatenated URL', function () {
|
||||
socialUrls.twitterUrl('myusername').should.eql('https://twitter.com/myusername');
|
||||
social.urls.twitter('myusername').should.eql('https://twitter.com/myusername');
|
||||
});
|
||||
|
||||
it('should return a url without an @ sign if one is provided', function () {
|
||||
socialUrls.twitterUrl('@myusername').should.eql('https://twitter.com/myusername');
|
||||
social.urls.twitter('@myusername').should.eql('https://twitter.com/myusername');
|
||||
});
|
||||
});
|
||||
|
||||
describe('facebook', function () {
|
||||
it('should return a correct concatenated URL', function () {
|
||||
socialUrls.facebookUrl('myusername').should.eql('https://www.facebook.com/myusername');
|
||||
social.urls.facebook('myusername').should.eql('https://www.facebook.com/myusername');
|
||||
});
|
||||
|
||||
it('should return a correct concatenated URL for usernames with slashes', function () {
|
||||
socialUrls.facebookUrl('page/xxx/123').should.eql('https://www.facebook.com/page/xxx/123');
|
||||
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 () {
|
||||
socialUrls.facebookUrl('/page/xxx/123').should.eql('https://www.facebook.com/page/xxx/123');
|
||||
social.urls.facebook('/page/xxx/123').should.eql('https://www.facebook.com/page/xxx/123');
|
||||
});
|
||||
});
|
||||
});
|
|
@ -52,8 +52,8 @@ describe('Mail: Utils', function () {
|
|||
logo: 'http://myblog.com/content/images/blog-logo.jpg',
|
||||
title: 'The Ghost Blog',
|
||||
url: 'http://myblog.com',
|
||||
twitterUrl: 'http://twitter.com/tryghost',
|
||||
facebookUrl: 'https://www.facebook.com/ghost',
|
||||
twitter: 'http://twitter.com/tryghost',
|
||||
facebook: 'https://www.facebook.com/ghost',
|
||||
unsubscribe: 'http://myblog.com/unsubscribe',
|
||||
post: [
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue