From dc110e2e3ff4fe8cc095f9d5b09bfaccb2c628db Mon Sep 17 00:00:00 2001 From: Baris Usakli <barisusakli@gmail.com> Date: Tue, 11 Jul 2017 13:44:51 -0400 Subject: [PATCH 1/5] closes #5818 --- src/meta/tags.js | 6 +++--- src/middleware/header.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/meta/tags.js b/src/meta/tags.js index 34ed3c43a9..0938980f22 100644 --- a/src/meta/tags.js +++ b/src/meta/tags.js @@ -10,7 +10,7 @@ var Meta = require('../meta'); var Tags = module.exports; -Tags.parse = function (req, meta, link, callback) { +Tags.parse = function (req, data, meta, link, callback) { async.parallel({ tags: function (next) { var defaultTags = [{ @@ -50,7 +50,7 @@ Tags.parse = function (req, meta, link, callback) { }); } - plugins.fireHook('filter:meta.getMetaTags', defaultTags, next); + plugins.fireHook('filter:meta.getMetaTags', { req: req, data: data, defaultTags: defaultTags }, next); }, links: function (next) { var defaultLinks = [{ @@ -101,7 +101,7 @@ Tags.parse = function (req, meta, link, callback) { href: nconf.get('relative_path') + '/assets/uploads/system/touchicon-192.png', }); } - plugins.fireHook('filter:meta.getLinkTags', defaultLinks, next); + plugins.fireHook('filter:meta.getLinkTags', { req: req, data: data, defaultLinks: defaultLinks }, next); }, }, function (err, results) { if (err) { diff --git a/src/middleware/header.js b/src/middleware/header.js index fe95b11a27..a30034df69 100644 --- a/src/middleware/header.js +++ b/src/middleware/header.js @@ -105,7 +105,7 @@ module.exports = function (middleware) { }); }, navigation: async.apply(navigation.get), - tags: async.apply(meta.tags.parse, req, res.locals.metaTags, res.locals.linkTags), + tags: async.apply(meta.tags.parse, req, data, res.locals.metaTags, res.locals.linkTags), banned: async.apply(user.isBanned, req.uid), banReason: async.apply(user.getBannedReason, req.uid), }, next); From 2d875a99cb6e27b9b16d6fc9dfd45931dfdedb51 Mon Sep 17 00:00:00 2001 From: Baris Usakli <barisusakli@gmail.com> Date: Tue, 11 Jul 2017 13:59:29 -0400 Subject: [PATCH 2/5] fix data --- src/meta/tags.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/meta/tags.js b/src/meta/tags.js index 0938980f22..4224f85dee 100644 --- a/src/meta/tags.js +++ b/src/meta/tags.js @@ -108,7 +108,7 @@ Tags.parse = function (req, data, meta, link, callback) { return callback(err); } - meta = results.tags.concat(meta || []).map(function (tag) { + meta = results.tags.defaultTags.concat(meta || []).map(function (tag) { if (!tag || typeof tag.content !== 'string') { winston.warn('Invalid meta tag. ', tag); return tag; @@ -139,7 +139,7 @@ Tags.parse = function (req, data, meta, link, callback) { addIfNotExists(meta, 'property', 'og:image:height', 200); } - link = results.links.concat(link || []); + link = results.links.defaultLinks.concat(link || []); callback(null, { meta: meta, From 12d53c95ca4cfe972f5687235abedd91bc9716a0 Mon Sep 17 00:00:00 2001 From: Baris Usakli <barisusakli@gmail.com> Date: Tue, 11 Jul 2017 14:14:55 -0400 Subject: [PATCH 3/5] up composer --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c007894688..e56ff845c8 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "morgan": "^1.3.2", "mousetrap": "^1.5.3", "nconf": "~0.8.2", - "nodebb-plugin-composer-default": "4.4.19", + "nodebb-plugin-composer-default": "5.0.0", "nodebb-plugin-dbsearch": "2.0.4", "nodebb-plugin-emoji-extended": "1.1.1", "nodebb-plugin-emoji-one": "1.2.1", From 593ea572c9b172ae5c3cbc024de863cb51f23491 Mon Sep 17 00:00:00 2001 From: Baris Usakli <barisusakli@gmail.com> Date: Tue, 11 Jul 2017 14:32:57 -0400 Subject: [PATCH 4/5] up markdown --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e56ff845c8..6592fe6b18 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "nodebb-plugin-dbsearch": "2.0.4", "nodebb-plugin-emoji-extended": "1.1.1", "nodebb-plugin-emoji-one": "1.2.1", - "nodebb-plugin-markdown": "7.1.2", + "nodebb-plugin-markdown": "8.0.0", "nodebb-plugin-mentions": "2.1.5", "nodebb-plugin-soundpack-default": "1.0.0", "nodebb-plugin-spam-be-gone": "0.5.0", From 701ba7388372547e5711d8c5c513d5b186f80729 Mon Sep 17 00:00:00 2001 From: Julian Lam <julian@nodebb.org> Date: Tue, 11 Jul 2017 15:40:41 -0400 Subject: [PATCH 5/5] updated homepage route logic so that it is all contained in the local function (and plugin hook receives all entries, including custom) @barisusakli --- src/controllers/accounts/settings.js | 59 +++++++++++++++++----------- 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/src/controllers/accounts/settings.js b/src/controllers/accounts/settings.js index 2f360f883c..0bcdc75c9c 100644 --- a/src/controllers/accounts/settings.js +++ b/src/controllers/accounts/settings.js @@ -34,9 +34,6 @@ settingsController.get = function (req, res, callback) { languages: function (next) { languages.list(next); }, - homePageRoutes: function (next) { - getHomePageRoutes(next); - }, soundsMapping: function (next) { meta.sounds.getUserSoundMap(userData.uid, next); }, @@ -45,7 +42,6 @@ settingsController.get = function (req, res, callback) { function (results, next) { userData.settings = results.settings; userData.languages = results.languages; - userData.homePageRoutes = results.homePageRoutes; var types = [ 'notification', @@ -89,6 +85,12 @@ settingsController.get = function (req, res, callback) { plugins.fireHook('filter:user.customSettings', { settings: results.settings, customSettings: [], uid: req.uid }, next); }, + function (data, next) { + getHomePageRoutes(userData, function (err, routes) { + userData.homePageRoutes = routes; + next(err, data); + }); + }, function (data, next) { userData.customSettings = data.customSettings; userData.disableEmailSubscriptions = parseInt(meta.config.disableEmailSubscriptions, 10) === 1; @@ -128,24 +130,6 @@ settingsController.get = function (req, res, callback) { { name: 'Yeti', value: 'yeti' }, ]; - var isCustom = true; - userData.homePageRoutes.forEach(function (route) { - route.selected = route.route === userData.settings.homePageRoute; - if (route.selected) { - isCustom = false; - } - }); - - if (isCustom && userData.settings.homePageRoute === 'none') { - isCustom = false; - } - - userData.homePageRoutes.push({ - route: 'custom', - name: 'Custom', - selected: isCustom, - }); - userData.bootswatchSkinOptions.forEach(function (skin) { skin.selected = skin.value === userData.settings.bootswatchSkin; }); @@ -168,7 +152,7 @@ settingsController.get = function (req, res, callback) { }; -function getHomePageRoutes(callback) { +function getHomePageRoutes(userData, callback) { async.waterfall([ function (next) { db.getSortedSetRange('cid:0:children', 0, -1, next); @@ -206,9 +190,36 @@ function getHomePageRoutes(callback) { route: 'popular', name: 'Popular', }, - ].concat(categoryData) }, next); + ].concat(categoryData, [ + { + route: 'custom', + name: 'Custom', + }, + ]) }, next); }, function (data, next) { + // Set selected for each route + var customIdx; + var hasSelected = false; + data.routes = data.routes.map(function (route, idx) { + if (route.route === userData.settings.homePageRoute) { + route.selected = true; + hasSelected = true; + } else { + route.selected = false; + } + + if (route.route === 'custom') { + customIdx = idx; + } + + return route; + }); + + if (!hasSelected && customIdx && userData.settings.homePageRoute !== 'none') { + data.routes[customIdx].selected = true; + } + next(null, data.routes); }, ], callback);