diff --git a/src/meta/build.js b/src/meta/build.js index 2c82459777..9ba5ec89bf 100644 --- a/src/meta/build.js +++ b/src/meta/build.js @@ -5,7 +5,7 @@ var winston = require('winston'); var buildStart; -var valid = ['js', 'clientCSS', 'acpCSS', 'tpl', 'lang', 'sound', 'osd']; +var valid = ['js', 'clientCSS', 'acpCSS', 'tpl', 'lang', 'sound']; exports.buildAll = function (callback) { exports.build(valid.join(','), callback); @@ -117,12 +117,6 @@ exports.buildTargets = function (targets, callback) { meta.sounds.build(step.bind(this, startTime, target, next)); break; - case 'osd': - winston.info('[build] Building OpenSearchDocument XML'); - startTime = Date.now(); - meta.osd.build(step.bind(this, startTime, target, next)); - break; - default: winston.warn('[build] Unknown build target: \'' + target + '\''); setImmediate(next); diff --git a/src/meta/osd.js b/src/meta/osd.js index 05763baf50..4111a463d0 100644 --- a/src/meta/osd.js +++ b/src/meta/osd.js @@ -1,15 +1,13 @@ 'use strict'; -var path = require('path'); var xml = require('xml'); -var fs = require('fs'); var nconf = require('nconf'); -var osdFilePath = path.join(__dirname, '../../build/public/osd.xml'); +var plugins = require('../plugins'); module.exports = function (Meta) { Meta.osd = {}; - Meta.osd.build = function (callback) { + function generateXML () { var osdObject = { OpenSearchDescription: [ { @@ -36,6 +34,12 @@ module.exports = function (Meta) { }, ], }; - fs.writeFile(osdFilePath, xml([osdObject], { declaration: true, indent: '\t' }), callback); + 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(); }; }; diff --git a/src/meta/tags.js b/src/meta/tags.js index d54a07addc..5b1097d427 100644 --- a/src/meta/tags.js +++ b/src/meta/tags.js @@ -65,7 +65,7 @@ module.exports = function (Meta) { defaultLinks.push({ rel: 'search', type: 'application/opensearchdescription+xml', - href: nconf.get('relative_path') + '/assets/osd.xml', + href: nconf.get('relative_path') + '/osd.xml', }); } diff --git a/src/routes/meta.js b/src/routes/meta.js index cfeeac5b9b..0d97468c84 100644 --- a/src/routes/meta.js +++ b/src/routes/meta.js @@ -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', require('../meta').osd.handleOSDRequest); };