mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-22 22:50:53 +01:00
Merge pull request #5501 from RoiEXLab/add-osd-functionality
Add OpenSearchDocument XML (#5399)
This commit is contained in:
@@ -94,6 +94,7 @@
|
||||
"underscore.deep": "^0.5.1",
|
||||
"validator": "^6.1.0",
|
||||
"winston": "^2.1.0",
|
||||
"xml": "^1.0.1",
|
||||
"xregexp": "~3.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -30,6 +30,7 @@ Controllers.admin = require('./admin');
|
||||
Controllers.globalMods = require('./globalmods');
|
||||
Controllers.mods = require('./mods');
|
||||
Controllers.sitemap = require('./sitemap');
|
||||
Controllers.osd = require('./osd');
|
||||
Controllers['404'] = require('./404');
|
||||
Controllers.errors = require('./errors');
|
||||
|
||||
|
||||
32
src/controllers/osd.js
Normal file
32
src/controllers/osd.js
Normal file
@@ -0,0 +1,32 @@
|
||||
'use strict';
|
||||
|
||||
var xml = require('xml');
|
||||
var nconf = require('nconf');
|
||||
|
||||
var plugins = require('../plugins');
|
||||
var meta = require('../meta');
|
||||
|
||||
module.exports.handle = 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' });
|
||||
}
|
||||
@@ -61,6 +61,14 @@ module.exports = function (Meta) {
|
||||
href: nconf.get('relative_path') + '/manifest.json',
|
||||
}];
|
||||
|
||||
if (plugins.hasListeners('filter:search.query')) {
|
||||
defaultLinks.push({
|
||||
rel: 'search',
|
||||
type: 'application/opensearchdescription+xml',
|
||||
href: nconf.get('relative_path') + '/osd.xml',
|
||||
});
|
||||
}
|
||||
|
||||
// Touch icons for mobile-devices
|
||||
if (Meta.config['brand:touchIcon']) {
|
||||
defaultLinks.push({
|
||||
|
||||
@@ -8,4 +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', controllers.osd.handle);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user