Refactor Code

v1.18.x
RoiEX 8 years ago
parent 710377ceea
commit 186c1f40e9

@ -32,6 +32,7 @@ Controllers.mods = require('./mods');
Controllers.sitemap = require('./sitemap'); Controllers.sitemap = require('./sitemap');
Controllers['404'] = require('./404'); Controllers['404'] = require('./404');
Controllers.errors = require('./errors'); Controllers.errors = require('./errors');
Controllers.handleOSDRequest = require('./osd');
Controllers.home = function (req, res, next) { Controllers.home = function (req, res, next) {
var route = meta.config.homePageRoute || (meta.config.homePageCustom || '').replace(/^\/+/, '') || 'categories'; var route = meta.config.homePageRoute || (meta.config.homePageCustom || '').replace(/^\/+/, '') || 'categories';

@ -0,0 +1,44 @@
'use strict';
var xml = require('xml');
var nconf = require('nconf');
var plugins = require('../plugins');
var meta = require('../meta');
module.exports = function (req, res, next) {
if (plugins.hasListeners('filter:search.query')) {
res.type('application/xml').send(generateXML());
} else {
next();
}
};
function generateXML() {
return xml([{
OpenSearchDescription: [
{
_attr: {
xmlns: 'http://a9.com/-/spec/opensearch/1.1/',
},
},
{
ShortName: String(meta.config.title || meta.config.browserTitle || 'NodeBB'),
},
{
Description: String(meta.config.description || ''),
},
{
Url: [
{
_attr: {
type: 'text/html',
method: 'get',
template: nconf.get('url') + '/search?term={searchTerms}&in=titlesposts',
},
},
],
},
],
}], { declaration: true, indent: '\t' });
}

@ -21,7 +21,6 @@ var utils = require('../public/src/utils');
require('./meta/errors')(Meta); require('./meta/errors')(Meta);
require('./meta/tags')(Meta); require('./meta/tags')(Meta);
require('./meta/dependencies')(Meta); require('./meta/dependencies')(Meta);
require('./meta/osd')(Meta);
Meta.templates = require('./meta/templates'); Meta.templates = require('./meta/templates');
Meta.blacklist = require('./meta/blacklist'); Meta.blacklist = require('./meta/blacklist');
Meta.languages = require('./meta/languages'); Meta.languages = require('./meta/languages');

@ -1,45 +0,0 @@
'use strict';
var xml = require('xml');
var nconf = require('nconf');
var plugins = require('../plugins');
module.exports = function (Meta) {
Meta.osd = {};
function generateXML() {
var osdObject = {
OpenSearchDescription: [
{
_attr: {
xmlns: 'http://a9.com/-/spec/opensearch/1.1/',
},
},
{
ShortName: String(Meta.config.title || Meta.config.browserTitle || 'NodeBB'),
},
{
Description: String(Meta.config.description || ''),
},
{
Url: [
{
_attr: {
type: 'text/html',
method: 'get',
template: nconf.get('url') + '/search?term={searchTerms}&in=titlesposts',
},
},
],
},
],
};
return xml([osdObject], { declaration: true, indent: '\t' });
}
Meta.osd.handleOSDRequest = function (req, res, next) {
if (plugins.hasListeners('filter:search.query')) {
res.type('application/xml').send(generateXML());
}
next();
};
};

@ -8,5 +8,5 @@ module.exports = function (app, middleware, controllers) {
app.get('/robots.txt', controllers.robots); app.get('/robots.txt', controllers.robots);
app.get('/manifest.json', controllers.manifest); app.get('/manifest.json', controllers.manifest);
app.get('/css/previews/:theme', controllers.admin.themes.get); app.get('/css/previews/:theme', controllers.admin.themes.get);
app.get('/osd.xml', require('../meta').osd.handleOSDRequest); app.get('/osd.xml', controllers.handleOSDRequest);
}; };

Loading…
Cancel
Save