mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-22 16:30:34 +01:00
added String parsing library, sanitizing meta tag "description" for
topics, and added og:description meta tag -- fixes #688
This commit is contained in:
@@ -43,7 +43,8 @@
|
|||||||
"nodebb-theme-vanilla": "~0.0.10",
|
"nodebb-theme-vanilla": "~0.0.10",
|
||||||
"nodebb-theme-cerulean": "0.0.10",
|
"nodebb-theme-cerulean": "0.0.10",
|
||||||
"cron": "~1.0.1",
|
"cron": "~1.0.1",
|
||||||
"semver": "~2.2.1"
|
"semver": "~2.2.1",
|
||||||
|
"string": "~1.7.0"
|
||||||
},
|
},
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
"redis": "0.8.3",
|
"redis": "0.8.3",
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ var path = require('path'),
|
|||||||
winston = require('winston'),
|
winston = require('winston'),
|
||||||
validator = require('validator'),
|
validator = require('validator'),
|
||||||
async = require('async'),
|
async = require('async'),
|
||||||
|
S = require('string'),
|
||||||
|
|
||||||
pkg = require('../package.json'),
|
pkg = require('../package.json'),
|
||||||
|
|
||||||
@@ -507,8 +508,17 @@ var path = require('path'),
|
|||||||
},
|
},
|
||||||
function (topicData, next) {
|
function (topicData, next) {
|
||||||
var lastMod = 0,
|
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++) {
|
for (var x = 0, numPosts = topicData.posts.length; x < numPosts; x++) {
|
||||||
timestamp = parseInt(topicData.posts[x].timestamp, 10);
|
timestamp = parseInt(topicData.posts[x].timestamp, 10);
|
||||||
@@ -520,34 +530,48 @@ var path = require('path'),
|
|||||||
app.build_header({
|
app.build_header({
|
||||||
req: req,
|
req: req,
|
||||||
res: res,
|
res: res,
|
||||||
metaTags: [{
|
metaTags: [
|
||||||
name: "title",
|
{
|
||||||
content: topicData.topic_name
|
name: "title",
|
||||||
}, {
|
content: topicData.topic_name
|
||||||
name: "description",
|
},
|
||||||
content: sanitize(topicData.posts[0].content.substr(0, 255)).escape().replace('\n', '')
|
{
|
||||||
}, {
|
name: "description",
|
||||||
property: 'og:title',
|
content: description
|
||||||
content: topicData.topic_name + ' | ' + (meta.config.title || 'NodeBB')
|
},
|
||||||
}, {
|
{
|
||||||
property: "og:type",
|
property: 'og:title',
|
||||||
content: 'article'
|
content: topicData.topic_name + ' | ' + (meta.config.title || 'NodeBB')
|
||||||
}, {
|
},
|
||||||
property: "og:url",
|
{
|
||||||
content: nconf.get('url') + 'topic/' + topicData.slug
|
property: 'og:description',
|
||||||
}, {
|
content: description
|
||||||
property: 'og:image',
|
},
|
||||||
content: topicData.posts[0].picture
|
{
|
||||||
}, {
|
property: "og:type",
|
||||||
property: "article:published_time",
|
content: 'article'
|
||||||
content: new Date(parseInt(topicData.posts[0].timestamp, 10)).toISOString()
|
},
|
||||||
}, {
|
{
|
||||||
property: 'article:modified_time',
|
property: "og:url",
|
||||||
content: new Date(lastMod).toISOString()
|
content: nconf.get('url') + 'topic/' + topicData.slug
|
||||||
}, {
|
},
|
||||||
property: 'article:section',
|
{
|
||||||
content: topicData.category_name
|
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: [
|
linkTags: [
|
||||||
{
|
{
|
||||||
rel: 'alternate',
|
rel: 'alternate',
|
||||||
|
|||||||
Reference in New Issue
Block a user