Added meta data to user profile pages, and also added noEscape
option to meta tag input. If set, validator escaping won't be
run on that value.
v1.18.x
Julian Lam 10 years ago
parent dbe5b963bd
commit 34725ec3e5

@ -2,6 +2,7 @@
var nconf = require('nconf'), var nconf = require('nconf'),
async = require('async'), async = require('async'),
S = require('string'),
user = require('../../user'), user = require('../../user'),
posts = require('../../posts'), posts = require('../../posts'),
@ -80,6 +81,42 @@ profileController.get = function(req, res, callback) {
userData.profileviews = 1; userData.profileviews = 1;
} }
var plainAboutMe = S(userData.aboutme).decodeHTMLEntities().stripTags().s;
res.locals.metaTags = [
{
name: "title",
content: userData.fullname || userData.username
},
{
name: "description",
content: plainAboutMe
},
{
property: 'og:title',
content: userData.fullname || userData.username
},
{
property: 'og:description',
content: plainAboutMe
}
];
if (userData.picture) {
res.locals.metaTags.push(
{
property: 'og:image',
content: userData.picture,
noEscape: true
},
{
property: "og:image:url",
content: userData.picture,
noEscape: true
}
);
}
plugins.fireHook('filter:user.account', {userData: userData, uid: req.uid}, next); plugins.fireHook('filter:user.account', {userData: userData, uid: req.uid}, next);
} }
], function(err, results) { ], function(err, results) {

@ -203,15 +203,18 @@ topicsController.get = function(req, res, callback) {
}, },
{ {
property: "og:url", property: "og:url",
content: nconf.get('url') + '/topic/' + topicData.slug + (req.params.post_index ? ('/' + req.params.post_index) : '') content: nconf.get('url') + '/topic/' + topicData.slug + (req.params.post_index ? ('/' + req.params.post_index) : ''),
noEscape: true
}, },
{ {
property: 'og:image', property: 'og:image',
content: ogImageUrl content: ogImageUrl,
noEscape: true
}, },
{ {
property: "og:image:url", property: "og:image:url",
content: ogImageUrl content: ogImageUrl,
noEscape: true
}, },
{ {
property: "article:published_time", property: "article:published_time",

@ -32,10 +32,12 @@ module.exports = function(Meta) {
content: Meta.config.keywords || '' content: Meta.config.keywords || ''
}, { }, {
name: 'msapplication-badge', name: 'msapplication-badge',
content: 'frequency=30; polling-uri=' + nconf.get('url') + '/sitemap.xml' content: 'frequency=30; polling-uri=' + nconf.get('url') + '/sitemap.xml',
noEscape: true
}, { }, {
name: 'msapplication-square150x150logo', name: 'msapplication-square150x150logo',
content: Meta.config['brand:logo'] || '' content: Meta.config['brand:logo'] || '',
noEscape: true
}]; }];
plugins.fireHook('filter:meta.getMetaTags', defaultTags, next); plugins.fireHook('filter:meta.getMetaTags', defaultTags, next);
}, },
@ -89,7 +91,10 @@ module.exports = function(Meta) {
return tag; return tag;
} }
tag.content = validator.escape(tag.content); if (!tag.noEscape) {
tag.content = validator.escape(tag.content);
}
return tag; return tag;
}); });

Loading…
Cancel
Save