Skip to content

Node.js based forum software built for the modern web

first pass at meta tag construction abstraction (issue #116). Also addressed issue #118

Julian Lamcc1cc7cae4b0
diff --git a/public/src/utils.js b/public/src/utils.js
index cc94905bd8..6f27bd7bce 100644
--- a/public/src/utils.js
+++ b/public/src/utils.js
@@ -107,6 +107,23 @@
return input.replace(commentsAndPhpTags, '').replace(tags, function ($0, $1) {
return allowed.indexOf('<' + $1.toLowerCase() + '>') > -1 ? $0 : '';
});
+ },
+
+ buildMetaTags: function(tagsArr) {
+ var tags = '',
+ tag;
+ for(var x=0,numTags=tagsArr.length;x<numTags;x++) {
+ if (tags.length > 0) tags += "\n\t";
+ tag = '<meta';
+ for(y in tagsArr[x]) {
+ tag += ' ' + y + '="' + tagsArr[x][y] + '"';
+ }
+ tag += ' />';
+
+ tags += tag;
+ }
+
+ return tags;
}
}
diff --git a/public/templates/header.tpl b/public/templates/header.tpl
index 2215f0b742..f960144fdf 100644
--- a/public/templates/header.tpl
+++ b/public/templates/header.tpl
@@ -2,12 +2,7 @@
<html>
<head>
<title>{title}</title>
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta name="title" CONTENT="NodeBB">
- <meta name="keywords" content="" />
- <meta name="description" content="{meta.description}" />
- <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
- <meta name="apple-mobile-web-app-capable" content="yes" />
+ {meta_tags}
<link href="{cssSrc}" rel="stylesheet" media="screen">
<link href="{relative_path}/vendor/bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">
<link rel="stylesheet" href="{relative_path}/vendor/fontawesome/css/font-awesome.min.css">
diff --git a/src/categories.js b/src/categories.js
index 4bd644bf24..ea4b4ec01d 100644
--- a/src/categories.js
+++ b/src/categories.js
@@ -13,7 +13,8 @@ var RDB = require('./redis.js'),
if (err) return callback(err);
var category_name = categoryData.name,
- category_slug = categoryData.slug;
+ category_slug = categoryData.slug,
+ category_description = categoryData.description;
function getTopicIds(next) {
Categories.getTopicIds(category_id, next);
@@ -28,6 +29,7 @@ var RDB = require('./redis.js'),
var categoryData = {
'category_name' : category_name,
+ 'category_description': category_description,
'show_sidebar' : 'show',
'show_topic_button': 'inline-block',
'no_topics_message': 'hidden',
diff --git a/src/webserver.js b/src/webserver.js
index 3065d71b99..c2555b1400 100644
--- a/src/webserver.js
+++ b/src/webserver.js
@@ -26,15 +26,20 @@ var express = require('express'),
(function(app) {
var templates = null;
- app.build_header = function(res) {
+ app.build_header = function(res, metaTags) {
+ var defaultMetaTags = [
+ { name: 'viewport', content: 'width=device-width, initial-scale=1.0' },
+ { name: 'content-type', content: 'text/html; charset=UTF-8' },
+ { name: 'apple-mobile-web-app-capable', content: 'yes' }
+ ],
+ metaString = utils.buildMetaTags(defaultMetaTags.concat(metaTags || []));
+
return templates['header'].parse({
cssSrc: global.config['theme:src'] || global.nconf.get('relative_path') + '/vendor/bootstrap/css/bootstrap.min.css',
title: global.config['title'] || 'NodeBB',
csrf:res.locals.csrf_token,
relative_path: global.nconf.get('relative_path'),
- meta: {
- description: 'test'
- }
+ meta_tags: metaString
});
};
@@ -157,7 +162,6 @@ var express = require('express'),
app.get('/', function(req, res) {
-
categories.getAllCategories(function(returnData) {
res.send(
app.build_header(res) +
@@ -214,9 +218,12 @@ var express = require('express'),
var category_url = cid + (req.params.slug ? '/' + req.params.slug : '');
categories.getCategoryById(cid, 0, function(err, returnData) {
if(err) return res.redirect('404');
-
+
res.send(
- app.build_header(res) +
+ app.build_header(res, [
+ { name: 'title', content: returnData.category_name },
+ { name: 'description', content: returnData.category_description }
+ ]) +
'\n\t<noscript>\n' + templates['noscript/header'] + templates['noscript/category'].parse(returnData) + '\n\t</noscript>' +
'\n\t<script>templates.ready(function(){ajaxify.go("category/' + category_url + '");});</script>' +
templates['footer']