fix(opensearch): Implement dynamic OpenSearch XML generation and update layout reference

This commit is contained in:
Willie Zutz
2025-05-08 00:39:17 -06:00
parent ddfe8c607d
commit d839769d7e
3 changed files with 27 additions and 10 deletions

View File

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
<ShortName>Perplexica</ShortName>
<Description>Search with Perplexica AI</Description>
<InputEncoding>UTF-8</InputEncoding>
<Image width="16" height="16" type="image/x-icon">/favicon.ico</Image>
<Url type="text/html" template="/?q={searchTerms}"/>
<Url type="application/opensearchdescription+xml" rel="self" template="/opensearch.xml"/>
</OpenSearchDescription>

View File

@ -0,0 +1,26 @@
import { NextResponse } from 'next/server';
export async function GET(request: Request) {
// Get the host from the request
const url = new URL(request.url);
const origin = url.origin;
// Create the OpenSearch XML with the correct origin
const opensearchXml = `<?xml version="1.0" encoding="utf-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/">
<ShortName>Perplexica</ShortName>
<LongName>Search with Perplexica AI</LongName>
<Description>Perplexica is a powerful AI-driven search engine that understands your queries and delivers relevant results.</Description>
<InputEncoding>UTF-8</InputEncoding>
<Image width="16" height="16" type="image/x-icon">${origin}/favicon.ico</Image>
<Url type="text/html" template="${origin}/?q={searchTerms}"/>
<Url type="application/opensearchdescription+xml" rel="self" template="${origin}/api/opensearch"/>
</OpenSearchDescription>`;
// Return the XML with the correct content type
return new NextResponse(opensearchXml, {
headers: {
'Content-Type': 'application/opensearchdescription+xml',
},
});
}

View File

@ -31,7 +31,7 @@ export default function RootLayout({
rel="search"
type="application/opensearchdescription+xml"
title="Perplexica Search"
href="/opensearch.xml"
href="/api/opensearch"
/>
</head>
<body className={cn('h-full', montserrat.className)}>