mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-04 23:00:31 +01:00
Add Support for Firefox OSD
This commit is contained in:
@@ -77,8 +77,9 @@
|
||||
var type = tag.type ? 'type="' + tag.type + '" ' : '';
|
||||
var href = tag.href ? 'href="' + tag.href + '" ' : '';
|
||||
var sizes = tag.sizes ? 'sizes="' + tag.sizes + '" ' : '';
|
||||
var title = tag.title ? 'title="' + tag.title + '" ' : '';
|
||||
|
||||
return '<link ' + link + rel + type + sizes + href + '/>\n\t';
|
||||
return '<link ' + link + rel + type + sizes + title + href + '/>\n\t';
|
||||
}
|
||||
|
||||
function stringify(obj) {
|
||||
|
||||
@@ -8,7 +8,7 @@ var meta = require('../meta');
|
||||
|
||||
module.exports.handle = function (req, res, next) {
|
||||
if (plugins.hasListeners('filter:search.query')) {
|
||||
res.type('application/xml').send(generateXML());
|
||||
res.type('application/opensearchdescription+xml').send(generateXML());
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
@@ -17,9 +17,21 @@ module.exports.handle = function (req, res, 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 || '') },
|
||||
{ _attr: {
|
||||
xmlns: 'http://a9.com/-/spec/opensearch/1.1/',
|
||||
'xmlns:moz': 'http://www.mozilla.org/2006/browser/search/',
|
||||
} },
|
||||
{ ShortName: trimToLength(String(meta.config.title || meta.config.browserTitle || 'NodeBB'), 16) },
|
||||
{ Description: trimToLength(String(meta.config.description || ''), 1024) },
|
||||
{ InputEncoding: 'UTF-8' },
|
||||
{ Image: [
|
||||
{ _attr: {
|
||||
width: '16',
|
||||
height: '16',
|
||||
type: 'image/x-icon',
|
||||
} },
|
||||
nconf.get('url') + '/favicon.ico',
|
||||
] },
|
||||
{ Url: {
|
||||
_attr: {
|
||||
type: 'text/html',
|
||||
@@ -27,6 +39,11 @@ function generateXML() {
|
||||
template: nconf.get('url') + '/search?term={searchTerms}&in=titlesposts',
|
||||
},
|
||||
} },
|
||||
{ 'moz:SearchForm': nconf.get('url') + '/search' },
|
||||
],
|
||||
}], { declaration: true, indent: '\t' });
|
||||
}
|
||||
|
||||
function trimToLength(string, length) {
|
||||
return string.trim().substring(0, length).trim();
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@ Tags.parse = function (req, data, meta, link, callback) {
|
||||
defaultLinks.push({
|
||||
rel: 'search',
|
||||
type: 'application/opensearchdescription+xml',
|
||||
title: validator.escape(String(Meta.config.title || Meta.config.browserTitle || 'NodeBB')),
|
||||
href: nconf.get('relative_path') + '/osd.xml',
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user