From 123e490311b76e41ccd6781adf1cde135f84de9a Mon Sep 17 00:00:00 2001 From: Soni L Date: Wed, 28 Dec 2022 19:53:59 -0300 Subject: [PATCH] Support OpenSearch (closes #7058) (#9427) Co-authored-by: Chaos --- .../src/server/web/ClientServerService.ts | 19 +++++++++++++++++++ .../backend/src/server/web/views/base.pug | 1 + 2 files changed, 20 insertions(+) diff --git a/packages/backend/src/server/web/ClientServerService.ts b/packages/backend/src/server/web/ClientServerService.ts index 727bbc9d7b..2b3f0ce0f5 100644 --- a/packages/backend/src/server/web/ClientServerService.ts +++ b/packages/backend/src/server/web/ClientServerService.ts @@ -304,6 +304,24 @@ export class ClientServerService { return await reply.sendFile('/robots.txt', staticAssets); }); + // OpenSearch XML + fastify.get('/opensearch.xml', async (request, reply) => { + const meta = await this.metaService.fetch(); + + const name = meta.name || "Misskey"; + let content = ""; + content += ``; + content += `${name} Search`; + content += `${name} Search`; + content += `UTF-8`; + content += `${this.config.url}/favicon.ico`; + content += ``; + content += ``; + + reply.header('Content-Type', 'application/opensearchdescription+xml'); + return await reply.send(content); + }); + //#endregion const renderBase = async (reply: FastifyReply) => { @@ -313,6 +331,7 @@ export class ClientServerService { img: meta.bannerUrl, title: meta.name ?? 'Misskey', instanceName: meta.name ?? 'Misskey', + url: this.config.url, desc: meta.description, icon: meta.iconUrl, themeColor: meta.themeColor, diff --git a/packages/backend/src/server/web/views/base.pug b/packages/backend/src/server/web/views/base.pug index 0c3c5c9b7e..b472cff899 100644 --- a/packages/backend/src/server/web/views/base.pug +++ b/packages/backend/src/server/web/views/base.pug @@ -31,6 +31,7 @@ html link(rel='icon' href= icon || '/favicon.ico') link(rel='apple-touch-icon' href= icon || '/apple-touch-icon.png') link(rel='manifest' href='/manifest.json') + link(rel='search' type='application/opensearchdescription+xml' title=((title || "Misskey") + " Search") href=`${url}/opensearch.xml`) link(rel='prefetch' href='https://xn--931a.moe/assets/info.jpg') link(rel='prefetch' href='https://xn--931a.moe/assets/not-found.jpg') link(rel='prefetch' href='https://xn--931a.moe/assets/error.jpg')