if there is no description tag add one, fix missing winston

v1.18.x
barisusakli 10 years ago
parent 7c319c9b20
commit b4d465223a

@ -1,14 +1,18 @@
'use strict';
var nconf = require('nconf'), var nconf = require('nconf'),
validator = require('validator'), validator = require('validator'),
async = require('async'), async = require('async'),
winston = require('winston'),
plugins = require('../plugins'); plugins = require('../plugins');
module.exports = function(Meta) { module.exports = function(Meta) {
Meta.tags = {}; Meta.tags = {};
Meta.tags.parse = function(meta, link, callback) { Meta.tags.parse = function(meta, link, callback) {
async.parallel([ async.parallel({
async.apply(plugins.fireHook, 'filter:meta.getMetaTags', [{ tags: function(next) {
var defaultTags = [{
name: 'viewport', name: 'viewport',
content: 'width=device-width, initial-scale=1.0, user-scalable=no' content: 'width=device-width, initial-scale=1.0, user-scalable=no'
}, { }, {
@ -29,18 +33,23 @@ module.exports = function(Meta) {
}, { }, {
name: 'msapplication-square150x150logo', name: 'msapplication-square150x150logo',
content: Meta.config['brand:logo'] || '' content: Meta.config['brand:logo'] || ''
}]), }];
async.apply(plugins.fireHook, 'filter:meta.getLinkTags', [{ plugins.fireHook('filter:meta.getMetaTags', defaultTags, next);
},
links: function(next) {
var defaultLinks = [{
rel: "icon", rel: "icon",
type: "image/x-icon", type: "image/x-icon",
href: nconf.get('relative_path') + '/favicon.ico' href: nconf.get('relative_path') + '/favicon.ico'
}, { }, {
rel: 'apple-touch-icon', rel: 'apple-touch-icon',
href: nconf.get('relative_path') + '/apple-touch-icon' href: nconf.get('relative_path') + '/apple-touch-icon'
}]) }];
], function(err, tags) { plugins.fireHook('filter:meta.getLinkTags', defaultLinks, next);
meta = tags[0].concat(meta || []).map(function(tag) { }
if(!tag || typeof tag.content !== 'string') { }, function(err, results) {
meta = results.tags.concat(meta || []).map(function(tag) {
if (!tag || typeof tag.content !== 'string') {
winston.warn('Invalid meta tag. ', tag); winston.warn('Invalid meta tag. ', tag);
return tag; return tag;
} }
@ -49,7 +58,9 @@ module.exports = function(Meta) {
return tag; return tag;
}); });
link = tags[1].concat(link || []); addDescription(meta);
link = results.links.concat(link || []);
callback(null, { callback(null, {
meta: meta, meta: meta,
@ -57,4 +68,20 @@ module.exports = function(Meta) {
}); });
}); });
}; };
function addDescription(meta) {
var hasDescription = false;
meta.forEach(function(tag) {
if (tag.name === 'description') {
hasDescription = true;
}
});
if (!hasDescription) {
meta.push({
name: 'description',
content: validator.escape(Meta.config.description || '')
});
}
}
}; };
Loading…
Cancel
Save