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'),
|
var config = require('../../config'),
|
||||||
escapeExpression = require('../../services/themes/engine').escapeExpression,
|
escapeExpression = require('../../services/themes/engine').escapeExpression,
|
||||||
socialUrls = require('../../utils/social-urls'),
|
social = require('../../lib/social'),
|
||||||
_ = require('lodash');
|
_ = require('lodash');
|
||||||
|
|
||||||
function schemaImageObject(metaDataVal) {
|
function schemaImageObject(metaDataVal) {
|
||||||
|
@ -43,20 +43,20 @@ function trimSameAs(data, context) {
|
||||||
sameAs.push(escapeExpression(data.post.author.website));
|
sameAs.push(escapeExpression(data.post.author.website));
|
||||||
}
|
}
|
||||||
if (data.post.author.facebook) {
|
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) {
|
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') {
|
} else if (context === 'author') {
|
||||||
if (data.author.website) {
|
if (data.author.website) {
|
||||||
sameAs.push(escapeExpression(data.author.website));
|
sameAs.push(escapeExpression(data.author.website));
|
||||||
}
|
}
|
||||||
if (data.author.facebook) {
|
if (data.author.facebook) {
|
||||||
sameAs.push(socialUrls.facebookUrl(data.author.facebook));
|
sameAs.push(social.urls.facebook(data.author.facebook));
|
||||||
}
|
}
|
||||||
if (data.author.twitter) {
|
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) {
|
function getStructuredData(metaData) {
|
||||||
var structuredData,
|
var structuredData,
|
||||||
|
@ -21,8 +21,8 @@ function getStructuredData(metaData) {
|
||||||
'article:published_time': metaData.publishedDate,
|
'article:published_time': metaData.publishedDate,
|
||||||
'article:modified_time': metaData.modifiedDate,
|
'article:modified_time': metaData.modifiedDate,
|
||||||
'article:tag': metaData.keywords,
|
'article:tag': metaData.keywords,
|
||||||
'article:publisher': metaData.blog.facebook ? socialUrls.facebookUrl(metaData.blog.facebook) : undefined,
|
'article:publisher': metaData.blog.facebook ? social.urls.facebook(metaData.blog.facebook) : undefined,
|
||||||
'article:author': metaData.authorFacebook ? socialUrls.facebookUrl(metaData.authorFacebook) : undefined,
|
'article:author': metaData.authorFacebook ? social.urls.facebook(metaData.authorFacebook) : undefined,
|
||||||
'twitter:card': card,
|
'twitter:card': card,
|
||||||
'twitter:title': metaData.twitterTitle || metaData.metaTitle,
|
'twitter:title': metaData.twitterTitle || metaData.metaTitle,
|
||||||
'twitter:description': metaData.twitterDescription || metaData.excerpt || metaData.metaDescription,
|
'twitter:description': metaData.twitterDescription || metaData.excerpt || metaData.metaDescription,
|
||||||
|
|
|
@ -14,7 +14,7 @@ module.exports = function facebook_url(username, options) { // eslint-disable-li
|
||||||
}
|
}
|
||||||
|
|
||||||
if (username) {
|
if (username) {
|
||||||
return socialUrls.facebookUrl(username);
|
return socialUrls.facebook(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -62,7 +62,7 @@ module.exports = {
|
||||||
templates: require('./template'),
|
templates: require('./template'),
|
||||||
|
|
||||||
// Various utils, needs cleaning up / simplifying
|
// Various utils, needs cleaning up / simplifying
|
||||||
socialUrls: require('../utils/social-urls'),
|
socialUrls: require('../lib/social/urls'),
|
||||||
blogIcon: require('../lib/image/blog-icon'),
|
blogIcon: require('../lib/image/blog-icon'),
|
||||||
url: require('../services/url').utils,
|
url: require('../services/url').utils,
|
||||||
localUtils: require('./utils')
|
localUtils: require('./utils')
|
||||||
|
|
|
@ -14,7 +14,7 @@ module.exports = function twitter_url(username, options) { // eslint-disable-lin
|
||||||
}
|
}
|
||||||
|
|
||||||
if (username) {
|
if (username) {
|
||||||
return socialUrls.twitterUrl(username);
|
return socialUrls.twitter(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
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 '@'
|
// Creates the canonical twitter URL without the '@'
|
||||||
return 'https://twitter.com/' + username.replace(/^@/, '');
|
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
|
// Handles a starting slash, this shouldn't happen, but just in case
|
||||||
return 'https://www.facebook.com/' + username.replace(/^\//, '');
|
return 'https://www.facebook.com/' + username.replace(/^\//, '');
|
||||||
};
|
};
|
|
@ -1,38 +1,36 @@
|
||||||
var should = require('should'),
|
var should = require('should'),
|
||||||
|
social = require('../../../../server/lib/social');
|
||||||
|
|
||||||
// Stuff we are testing
|
describe('lib/social: urls', function () {
|
||||||
socialUrls = require('../../../server/utils/social-urls');
|
|
||||||
|
|
||||||
describe('Social Urls', function () {
|
|
||||||
it('should have a twitter url function', 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 () {
|
it('should have a facebook url function', function () {
|
||||||
should.exist(socialUrls.facebookUrl);
|
should.exist(social.urls.facebook);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('twitter', function () {
|
describe('twitter', function () {
|
||||||
it('should return a correct concatenated URL', 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 () {
|
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 () {
|
describe('facebook', function () {
|
||||||
it('should return a correct concatenated URL', 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 () {
|
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 () {
|
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',
|
logo: 'http://myblog.com/content/images/blog-logo.jpg',
|
||||||
title: 'The Ghost Blog',
|
title: 'The Ghost Blog',
|
||||||
url: 'http://myblog.com',
|
url: 'http://myblog.com',
|
||||||
twitterUrl: 'http://twitter.com/tryghost',
|
twitter: 'http://twitter.com/tryghost',
|
||||||
facebookUrl: 'https://www.facebook.com/ghost',
|
facebook: 'https://www.facebook.com/ghost',
|
||||||
unsubscribe: 'http://myblog.com/unsubscribe',
|
unsubscribe: 'http://myblog.com/unsubscribe',
|
||||||
post: [
|
post: [
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue