mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-29 10:06:13 +01:00
Refactor Code
This commit is contained in:
@@ -32,6 +32,7 @@ Controllers.mods = require('./mods');
|
||||
Controllers.sitemap = require('./sitemap');
|
||||
Controllers['404'] = require('./404');
|
||||
Controllers.errors = require('./errors');
|
||||
Controllers.handleOSDRequest = require('./osd');
|
||||
|
||||
Controllers.home = function (req, res, next) {
|
||||
var route = meta.config.homePageRoute || (meta.config.homePageCustom || '').replace(/^\/+/, '') || 'categories';
|
||||
|
||||
44
src/controllers/osd.js
Normal file
44
src/controllers/osd.js
Normal file
@@ -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/tags')(Meta);
|
||||
require('./meta/dependencies')(Meta);
|
||||
require('./meta/osd')(Meta);
|
||||
Meta.templates = require('./meta/templates');
|
||||
Meta.blacklist = require('./meta/blacklist');
|
||||
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('/manifest.json', controllers.manifest);
|
||||
app.get('/css/previews/:theme', controllers.admin.themes.get);
|
||||
app.get('/osd.xml', require('../meta').osd.handleOSDRequest);
|
||||
app.get('/osd.xml', controllers.handleOSDRequest);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user