From 13508ca7f95bb5f55e0e734a5f5a3458676f4bce Mon Sep 17 00:00:00 2001
From: barisusakli
Date: Tue, 22 Sep 2015 19:22:20 -0400
Subject: [PATCH] closes #3547
---
public/src/app.js | 2 +-
src/controllers/api.js | 1 +
src/middleware/middleware.js | 15 +++++++++++----
src/views/admin/settings/general.tpl | 6 ++++++
4 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/public/src/app.js b/public/src/app.js
index fb28443a99..69fb1da0db 100644
--- a/public/src/app.js
+++ b/public/src/app.js
@@ -292,8 +292,8 @@ app.cacheBuster = null;
app.refreshTitle = function(title) {
require(['translator'], function(translator) {
+ title = config.titleLayout.replace(/{/g, '{').replace(/}/g, '}').replace('{pageTitle}', title).replace('{browserTitle}', config.browserTitle);
translator.translate(title, function(translated) {
- translated = translated ? (translated + ' | ' + config.browserTitle) : config.browserTitle;
titleObj.titles[0] = translated;
app.alternatingTitle('');
});
diff --git a/src/controllers/api.js b/src/controllers/api.js
index 9065bf4719..5b8f2b2bb6 100644
--- a/src/controllers/api.js
+++ b/src/controllers/api.js
@@ -34,6 +34,7 @@ apiController.getConfig = function(req, res, next) {
config.version = nconf.get('version');
config.siteTitle = validator.escape(meta.config.title || meta.config.browserTitle || 'NodeBB');
config.browserTitle = validator.escape(meta.config.browserTitle || meta.config.title || 'NodeBB');
+ config.titleLayout = (meta.config.titleLayout || '{pageTitle} || {browserTitle}').replace(/{/g, '{').replace(/}/g, '}');
config.showSiteTitle = parseInt(meta.config.showSiteTitle, 10) === 1;
config.postDelay = meta.config.postDelay;
config.minimumTitleLength = meta.config.minimumTitleLength;
diff --git a/src/middleware/middleware.js b/src/middleware/middleware.js
index c0c96f872e..be2a97aa3f 100644
--- a/src/middleware/middleware.js
+++ b/src/middleware/middleware.js
@@ -237,9 +237,7 @@ middleware.renderHeader = function(req, res, data, callback) {
}
},
title: function(next) {
- var title = validator.escape(meta.config.browserTitle || meta.config.title || 'NodeBB');
- title = data.title ? (data.title + ' | ' + title) : title;
- next(null, title);
+ next(null, buildTitle(data.title));
},
isAdmin: function(next) {
user.isAdministrator(req.uid, next);
@@ -456,8 +454,17 @@ function redirectToLogin(req, res) {
return controllers.helpers.redirect(res, '/login');
}
+function buildTitle(pageTitle) {
+ var titleLayout = meta.config.titleLayout || '{pageTitle} | {browserTitle}';
+
+ var browserTitle = validator.escape(meta.config.browserTitle || meta.config.title || 'NodeBB');
+ pageTitle = pageTitle || '';
+ var title = titleLayout.replace('{pageTitle}', pageTitle).replace('{browserTitle}', browserTitle);
+ return title;
+}
+
function modifyTitle(obj) {
- var title = '[[pages:home]] | ' + validator.escape(meta.config.browserTitle || meta.config.title || 'NodeBB');
+ var title = buildTitle('[[pages:home]]');
obj.browserTitle = title;
if (obj.metaTags) {
diff --git a/src/views/admin/settings/general.tpl b/src/views/admin/settings/general.tpl
index dda578a529..ecad320279 100644
--- a/src/views/admin/settings/general.tpl
+++ b/src/views/admin/settings/general.tpl
@@ -22,6 +22,12 @@
If no browser title is specified, the site title will be used
+
+
+
+ Define how the browser title will be structured ie. {pageTitle} | {browserTitle}
+
+