added String parsing library, sanitizing meta tag "description" for

topics, and added og:description meta tag -- fixes #688
v1.18.x
Julian Lam 11 years ago
parent 4a11307b24
commit 2c6bf93eb5

@ -43,7 +43,8 @@
"nodebb-theme-vanilla": "~0.0.10",
"nodebb-theme-cerulean": "0.0.10",
"cron": "~1.0.1",
"semver": "~2.2.1"
"semver": "~2.2.1",
"string": "~1.7.0"
},
"optionalDependencies": {
"redis": "0.8.3",

@ -9,6 +9,7 @@ var path = require('path'),
winston = require('winston'),
validator = require('validator'),
async = require('async'),
S = require('string'),
pkg = require('../package.json'),
@ -507,8 +508,17 @@ var path = require('path'),
},
function (topicData, next) {
var lastMod = 0,
timestamp,
sanitize = validator.sanitize;
sanitize = validator.sanitize,
description = (function() {
var content = S(topicData.posts[0].content).stripTags();
if (content.length > 255) {
content = content.substr(0, 255) + '...';
}
return sanitize(content).escape();
})(),
timestamp;
for (var x = 0, numPosts = topicData.posts.length; x < numPosts; x++) {
timestamp = parseInt(topicData.posts[x].timestamp, 10);
@ -520,34 +530,48 @@ var path = require('path'),
app.build_header({
req: req,
res: res,
metaTags: [{
name: "title",
content: topicData.topic_name
}, {
name: "description",
content: sanitize(topicData.posts[0].content.substr(0, 255)).escape().replace('\n', '')
}, {
property: 'og:title',
content: topicData.topic_name + ' | ' + (meta.config.title || 'NodeBB')
}, {
property: "og:type",
content: 'article'
}, {
property: "og:url",
content: nconf.get('url') + 'topic/' + topicData.slug
}, {
property: 'og:image',
content: topicData.posts[0].picture
}, {
property: "article:published_time",
content: new Date(parseInt(topicData.posts[0].timestamp, 10)).toISOString()
}, {
property: 'article:modified_time',
content: new Date(lastMod).toISOString()
}, {
property: 'article:section',
content: topicData.category_name
}],
metaTags: [
{
name: "title",
content: topicData.topic_name
},
{
name: "description",
content: description
},
{
property: 'og:title',
content: topicData.topic_name + ' | ' + (meta.config.title || 'NodeBB')
},
{
property: 'og:description',
content: description
},
{
property: "og:type",
content: 'article'
},
{
property: "og:url",
content: nconf.get('url') + 'topic/' + topicData.slug
},
{
property: 'og:image',
content: topicData.posts[0].picture
},
{
property: "article:published_time",
content: new Date(parseInt(topicData.posts[0].timestamp, 10)).toISOString()
},
{
property: 'article:modified_time',
content: new Date(lastMod).toISOString()
},
{
property: 'article:section',
content: topicData.category_name
}
],
linkTags: [
{
rel: 'alternate',

Loading…
Cancel
Save