Add opensearch.xml to site
This commit is contained in:
33
scripts/generateOpenSearch.ts
Normal file
33
scripts/generateOpenSearch.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
// Get the current file's directory
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
// Get the Bang URL from environment or use a default for local development
|
||||
const bangUrl = process.env.VITE_BANG_URL || 'https://bang.gbrown.org';
|
||||
|
||||
// Create the OpenSearch XML content
|
||||
const openSearchXml = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
|
||||
<ShortName>Bang!</ShortName>
|
||||
<Description>A better default search engine with bangs</Description>
|
||||
<InputEncoding>UTF-8</InputEncoding>
|
||||
<Image width="16" height="16" type="image/svg+xml">${bangUrl}/bang.svg</Image>
|
||||
<Url type="text/html" method="get" template="${bangUrl}?q={searchTerms}"/>
|
||||
<Url type="application/opensearchdescription+xml" rel="self" template="${bangUrl}/opensearch.xml"/>
|
||||
<moz:SearchForm xmlns:moz="http://www.mozilla.org/2006/browser/search/">${bangUrl}</moz:SearchForm>
|
||||
</OpenSearchDescription>`;
|
||||
|
||||
// Ensure the public directory exists
|
||||
const publicDir = path.resolve(__dirname, '../public');
|
||||
if (!fs.existsSync(publicDir)) {
|
||||
fs.mkdirSync(publicDir, { recursive: true });
|
||||
}
|
||||
|
||||
// Write the OpenSearch XML file
|
||||
fs.writeFileSync(path.join(publicDir, 'opensearch.xml'), openSearchXml);
|
||||
|
||||
console.log('OpenSearch XML file generated successfully!');
|
Reference in New Issue
Block a user