Skip to content

Commit

Permalink
1.4.3 {!,+}ai & try fixing more auto generation of open-search.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
h.u.g.u.rp committed Jul 27, 2023
1 parent 9316659 commit 5b40049
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 76 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "i4k-find",
"version": "1.4.2",
"version": "1.4.3",
"description": "URL action engine",
"main": "src/index.js",
"type": "module",
Expand Down Expand Up @@ -36,7 +36,7 @@
"localStorageKey": "i4find",
"queryParamName": "q",
"shortName": "Find",
"description": "Find anything anywhere",
"description": "Find search",
"image": "https://internet4000.github.io/find/assets/favicon.ico",
"templateHTML": "https://internet4000.github.io/find/#q={searchTerms}",
"templateXML": "https://internet4000.github.io/find/assets/opensearch.xml",
Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class I4kFindSymbols {
uri: encodeURIComponent("!"),
engines: {
"?": `${window.location.href}/#q=!docs%20{}`,
"ai": `https://attention1.gitlab.io/ai-interface/#input={}`,
ai: "https://attention1.gitlab.io/ai-interface/#input={}",
docs: "https://github.com/internet4000/find/#{}",
c: "https://contacts.google.com/search/{}",
cdn: "https://www.jsdelivr.com/?query={}",
Expand Down Expand Up @@ -58,6 +58,7 @@ export class I4kFindSymbols {
name: "do",
uri: encodeURIComponent("+"),
engines: {
ai: "https://attention1.gitlab.io/ai-interface/#system={}&input={}",
aurl: "https://web.archive.org/save/{}",
draw: "https://docs.google.com/drawings/create?title={}",
/*
Expand Down
2 changes: 1 addition & 1 deletion src/open-search.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const DEFAULT_OSD = {
shortName: "Find",
description: "Find Search",
description: "Find search",
image: "https://example.org/i4k-find/assets/favicon.ico",
templateHTML: "https://example.org/i4k-find/#q={searchTerms}",
templateXML: "https://example.org/i4k-find/assets/opensearch.xml",
Expand Down
72 changes: 23 additions & 49 deletions src/scripts/opensearch-xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,71 +32,45 @@ const newUserConfig = async (baseUrl) => {
userConfig.templateSuggestions = `${baseUrl}/api/suggestions/#${queryParamName}={searchTerms}`;
userConfig.image = `${baseUrl}/assets/favicon.ico`;
} catch(e) {
console.error("Wrong config site URL", e)
throw e
}
}
return userConfig;
};

const openSearchXml = async () => {
const { I4K_FIND_URL } = process.env;
if (!I4K_FIND_URL) {
throw "missing I4K_FIND_URL=https://example.org/my-find"
}
let newConfig;
try {
newConfig = await newUserConfig(I4K_FIND_URL);
} catch (e) {
console.error(e);
newConfig = config;
}
const {
shortName,
description,
image,
templateHTML,
templateXML,
templateSuggestions,
} = config
const osd = new OpenSearchDescription({
shortName,
description,
image,
templateHTML,
templateXML,
templateSuggestions,
});
const xmlOutput = osd.exportXML();
return xmlOutput
};

const init = async () => {
const argumementsUrlHash = process.argv[2]
let userArgs
try {
userArgs = new URLSearchParams(argumementsUrlHash)
} catch(e) {
/* console.log("No user scrip 'URL arguments'", process.argv) */
} catch(e) {}
const { generate = false } = userArgs
const { I4K_FIND_URL } = process.env;
if (!I4K_FIND_URL) {
return
}

const {
generate = false
} = userArgs
let osdXml;
try {
const newConfig = await newUserConfig(I4K_FIND_URL);
const osd = new OpenSearchDescription(newConfig);
osdXml = osd.exportXML();
} catch (e) {
console.error(e);o
return
}

const osdXml = await openSearchXml()
if (generate) {
if (outputPath) {
try {
const localPath = path.join(process.cwd(), OSD_PATH);
await path.resolve(localPath);
await fs.writeFile(localPath, osdXml);
} catch (e) {
throw(e);
}
if (osdXml && generate && outputPath) {
try {
const localPath = path.join(process.cwd(), OSD_PATH);
await path.resolve(localPath);
await fs.writeFile(localPath, osdXml);
} catch (e) {
throw(e);
}
}
return osdXml
}
init()
openSearchXml()

export default openSearchXml;
23 changes: 0 additions & 23 deletions src/tests/open-search-xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@ import find, { I4kFind } from "../index.js";
import { OpenSearchDescription } from "../open-search.js"
import openSearchXml from '../scripts/opensearch-xml.js'

const TEST_JSON = {
shortName: "Find",
description: "Find search",
image: "https://test.local/my-other-find/assets/favicon.ico",
templateHTML: "https://test.local/my-other-find/#q={searchTerms}",
templateXML: "https://test.local/my-other-find/assets/opensearch.xml",
templateSuggestions:
"https://test.local/my-other-find/api/suggestions/#q={searchTerms}",
};

const TEST_XML = `<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
<InputEncoding>UTF-8</InputEncoding>
Expand All @@ -28,21 +18,8 @@ test.afterEach(() => {
process.env.I4K_FIND_URL = '';
})

test("Not setting I4K_FIND_URL screams error", async (t) => {
process.env.I4K_FIND_URL = '';
t.throws(() => {
await openSearchXml()
});
})

test("Setting I4K_FIND_URL generates the OpenSearch XML", async (t) => {
process.env.I4K_FIND_URL = 'https://test.local/my-find';
const osdXml = await openSearchXml()
t.deepEqual(osdXml, TEST_XML);
})

test("Setting I4K_FIND_URL generates the OpenSearch JSON", async (t) => {
process.env.I4K_FIND_URL = 'https://test.local/my-other-find';
const osdJson = await openSearchJson()
t.deepEqual(osdJson, TEST_JSON);
})

0 comments on commit 5b40049

Please sign in to comment.