Node.js based forum software built for the modern web
applying custom theme (if enabled) to all routes
Julian Lam48bccb349848
diff --git a/public/templates/header.tpl b/public/templates/header.tplindex 2b95d4fe18..6adebc6f60 100644--- a/public/templates/header.tpl+++ b/public/templates/header.tpl@@ -5,8 +5,7 @@<meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="title" CONTENT="NodeBB"><meta name="description" content="Node.js/Redis/Socket.io powered forums for a new generation">- <link href="/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">- <!-- <link href="{cssSrc}" rel="stylesheet" media="screen"> -->+ <link href="{cssSrc}" rel="stylesheet" media="screen"><link href="/vendor/bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen"><link rel="stylesheet" href="/vendor/fontawesome/css/font-awesome.min.css"><script type="text/javascript" src="http://code.jquery.com/jquery.js"></script>diff --git a/src/routes/authentication.js b/src/routes/authentication.jsindex 3777e2f478..f84a375506 100644--- a/src/routes/authentication.js+++ b/src/routes/authentication.js@@ -81,11 +81,15 @@}Auth.create_routes = function(app) {+ var build_header = function() {+ return templates['header'].parse({ cssSrc: global.config['theme:src'] || '/vendor/bootstrap/css/bootstrap.min.css' });+ };+app.get('/logout', function(req, res) {console.log('info: [Auth] Session ' + req.sessionID + ' logout (uid: ' + global.uid + ')');user_module.logout(req.sessionID, function(logout) {req.logout();- res.send(templates['header'] + templates['logout'] + templates['footer']);+ res.send(build_header() + templates['logout'] + templates['footer']);});});@@ -119,11 +123,11 @@app.get('/reset/:code', function(req, res) {- res.send(templates['header'] + templates['reset_code'].parse({ reset_code: req.params.code }) + templates['footer']);+ res.send(build_header() + templates['reset_code'].parse({ reset_code: req.params.code }) + templates['footer']);});app.get('/reset', function(req, res) {- res.send(templates['header'] + templates['reset'] + templates['footer']);+ res.send(build_header() + templates['reset'] + templates['footer']);});diff --git a/src/routes/user.js b/src/routes/user.jsindex 6ec3a91103..b597d7f044 100644--- a/src/routes/user.js+++ b/src/routes/user.js@@ -6,7 +6,9 @@ var user = require('./../user.js'),(function(User) {User.create_routes = function(app) {-+ var build_header = function() {+ return templates['header'].parse({ cssSrc: global.config['theme:src'] || '/vendor/bootstrap/css/bootstrap.min.css' });+ };app.get('/uid/:uid', function(req, res) {@@ -23,24 +25,18 @@ var user = require('./../user.js'),});app.get('/users', function(req, res) {-user.getUserList(function(data) {-- res.send(templates['header'] + app.create_route("users", "users") + templates['footer']);-+ res.send(build_header() + app.create_route("users", "users") + templates['footer']);});-});app.get('/users/:username', function(req, res) {-if(!req.params.username) {res.send("User doesn't exist!");return;}user.get_uid_by_username(req.params.username, function(uid) {-if(!uid) {res.redirect('/403');return;@@ -48,7 +44,7 @@ var user = require('./../user.js'),user.getUserData(uid, function(data) {if(data) {- res.send(templates['header'] + app.create_route('users/'+data.username, 'account') + templates['footer']);+ res.send(build_header() + app.create_route('users/'+data.username, 'account') + templates['footer']);}else {res.redirect('/403');@@ -65,7 +61,7 @@ var user = require('./../user.js'),user.getUserField(req.user.uid, 'username', function(username) {if(req.params.username && username === req.params.username)- res.send(templates['header'] + app.create_route('users/'+req.params.username+'/edit','accountedit') + templates['footer']);+ res.send(build_header() + app.create_route('users/'+req.params.username+'/edit','accountedit') + templates['footer']);elsereturn res.redirect('/403');});@@ -231,7 +227,7 @@ var user = require('./../user.js'),if(!req.user)return res.redirect('/403');- res.send(templates['header'] + app.create_route('users/'+req.params.username+'/friends','friends') + templates['footer']);+ res.send(build_header() + app.create_route('users/'+req.params.username+'/friends','friends') + templates['footer']);});function api_method(req, res) {diff --git a/src/webserver.js b/src/webserver.jsindex 1b468c6476..13e2d448c3 100644--- a/src/webserver.js+++ b/src/webserver.js@@ -70,25 +70,23 @@ var express = require('express'),return '<script>templates.ready(function(){ajaxify.go("' + url + '", null, "' + tpl + '");});</script>';};-// Basic Routes (entirely client-side parsed, goal is to move the rest of the crap in this file into this one section)(function() {- var routes = ['', 'login', 'register', 'account', 'latest', 'popular', 'active', '403', '404'];+ var routes = ['', 'login', 'register', 'account', 'latest', 'popular', 'active', '403', '404'],+ build_header = function() {+ return templates['header'].parse({ cssSrc: global.config['theme:src'] || '/vendor/bootstrap/css/bootstrap.min.css' });+ };for (var i=0, ii=routes.length; i<ii; i++) {(function(route) {app.get('/' + route, function(req, res) {-if ((route === 'login' || route ==='register') && (req.user && req.user.uid > 0)) {res.redirect('/account');return;}- res.send(- templates['header'].parse({ cssSrc: global.config['theme:src'] || '/vendor/bootstrap/css/bootstrap.min.css' }) +- app.create_route(route) + templates['footer']- );+ res.send(build_header() + app.create_route(route) + templates['footer']);});}(routes[i]));}@@ -97,16 +95,16 @@ var express = require('express'),// Complex Routesapp.get('/topic/:topic_id/:slug?', function(req, res) {var topic_url = req.params.topic_id + (req.params.slug ? '/' + req.params.slug : '');- res.send(templates['header'] + '<script>templates.ready(function(){ajaxify.go("topic/' + topic_url + '");});</script>' + templates['footer']);+ res.send(build_header() + '<script>templates.ready(function(){ajaxify.go("topic/' + topic_url + '");});</script>' + templates['footer']);});app.get('/category/:category_id/:slug?', function(req, res) {var category_url = req.params.category_id + (req.params.slug ? '/' + req.params.slug : '');- res.send(templates['header'] + '<script>templates.ready(function(){ajaxify.go("category/' + category_url + '");});</script>' + templates['footer']);+ res.send(build_header() + '<script>templates.ready(function(){ajaxify.go("category/' + category_url + '");});</script>' + templates['footer']);});app.get('/confirm/:code', function(req, res) {- res.send(templates['header'] + '<script>templates.ready(function(){ajaxify.go("confirm/' + req.params.code + '");});</script>' + templates['footer']);+ res.send(build_header() + '<script>templates.ready(function(){ajaxify.go("confirm/' + req.params.code + '");});</script>' + templates['footer']);});// These functions are called via ajax once the initial page is loaded to populate templates with data