atmosphere explorer pds.ls
tool typescript atproto

Add OpenSearch support #21

closed opened by launchpadx.top targeting main

This PR enhances search functionality by adding OpenSearch support and enabling URL parameter search queries.

This is the same as https://tangled.org/pds.ls/pdsls/pulls/20, where I forgot to include all the modified files last time, and then Tangled seemed to be having some issues, preventing me from clicking "resubmit" so I created this new PR.

Labels

None yet.

assignee

None yet.

Participants 2
AT URI
at://did:plc:gcktt4t6eocohmc2f4rozxly/sh.tangled.repo.pull/3mdsqxcvpbh22
+68 -37
Diff #0
+1
.gitignore
··· 3 3 .env 4 4 .DS_Store 5 5 public/oauth-client-metadata.json 6 + public/opensearch.xml
+1
index.html
··· 10 10 <meta property="og:description" content="Browse the public data on atproto" /> 11 11 <meta property="description" content="Browse the public data on atproto" /> 12 12 <link rel="manifest" href="/manifest.json" /> 13 + <link rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml" title="PDSls"> 13 14 <link rel="preconnect" href="https://fonts.bunny.net" /> 14 15 <link href="https://fonts.bunny.net/css?family=roboto-mono:400" rel="stylesheet" /> 15 16 <link href="https://fonts.cdnfonts.com/css/pecita" rel="stylesheet" />
+2 -2
package.json
··· 4 4 "type": "module", 5 5 "scripts": { 6 6 "start": "vite", 7 - "predev": "node scripts/generate-oauth-metadata.js", 7 + "predev": "node scripts/generate-metadata.js", 8 8 "dev": "vite", 9 - "prebuild": "node scripts/generate-oauth-metadata.js", 9 + "prebuild": "node scripts/generate-metadata.js", 10 10 "build": "vite build", 11 11 "serve": "vite preview" 12 12 },
+56
scripts/generate-metadata.js
··· 1 + import { mkdirSync, writeFileSync } from "fs"; 2 + import { dirname } from "path"; 3 + import { fileURLToPath } from "url"; 4 + 5 + const __filename = fileURLToPath(import.meta.url); 6 + const __dirname = dirname(__filename); 7 + 8 + const domain = process.env.APP_DOMAIN || "pdsls.dev"; 9 + const protocol = process.env.APP_PROTOCOL || "https"; 10 + const baseUrl = `${protocol}://${domain}`; 11 + 12 + const configs = [ 13 + { 14 + name: "OAuth metadata", 15 + path: `${__dirname}/../public/oauth-client-metadata.json`, 16 + content: JSON.stringify({ 17 + client_id: `${baseUrl}/oauth-client-metadata.json`, 18 + client_name: "PDSls", 19 + client_uri: baseUrl, 20 + logo_uri: `${baseUrl}/favicon.ico`, 21 + redirect_uris: [`${baseUrl}/`], 22 + scope: "atproto repo:*?action=create repo:*?action=update repo:*?action=delete blob:*/*", 23 + grant_types: ["authorization_code", "refresh_token"], 24 + response_types: ["code"], 25 + token_endpoint_auth_method: "none", 26 + application_type: "web", 27 + dpop_bound_access_tokens: true, 28 + }, null, 2) + "\n" 29 + }, 30 + { 31 + name: "OpenSearch XML", 32 + path: `${__dirname}/../public/opensearch.xml`, 33 + content: `<?xml version="1.0" encoding="UTF-8"?> 34 + <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/"> 35 + <ShortName>PDSls</ShortName> 36 + <Description>Search the Atmosphere</Description> 37 + <InputEncoding>UTF-8</InputEncoding> 38 + <Image width="16" height="16" type="image/x-icon">${baseUrl}/favicon.ico</Image> 39 + <Url type="text/html" method="get" template="${baseUrl}/?q={searchTerms}"/> 40 + <moz:SearchForm>${baseUrl}</moz:SearchForm> 41 + </OpenSearchDescription>` 42 + } 43 + ]; 44 + 45 + try { 46 + mkdirSync(dirname(configs[0].path), { recursive: true }); 47 + 48 + configs.forEach(config => { 49 + writeFileSync(config.path, config.content); 50 + console.log(`Generated ${config.name} for ${baseUrl}`); 51 + }); 52 + 53 + } catch (error) { 54 + console.error("Failed to generate files:", error); 55 + process.exit(1); 56 + }
-35
scripts/generate-oauth-metadata.js
··· 1 - import { mkdirSync, writeFileSync } from "fs"; 2 - import { dirname } from "path"; 3 - import { fileURLToPath } from "url"; 4 - 5 - const __filename = fileURLToPath(import.meta.url); 6 - const __dirname = dirname(__filename); 7 - 8 - const domain = process.env.APP_DOMAIN || "pdsls.dev"; 9 - const protocol = process.env.APP_PROTOCOL || "https"; 10 - const baseUrl = `${protocol}://${domain}`; 11 - 12 - const metadata = { 13 - client_id: `${baseUrl}/oauth-client-metadata.json`, 14 - client_name: "PDSls", 15 - client_uri: baseUrl, 16 - logo_uri: `${baseUrl}/favicon.ico`, 17 - redirect_uris: [`${baseUrl}/`], 18 - scope: "atproto repo:*?action=create repo:*?action=update repo:*?action=delete blob:*/*", 19 - grant_types: ["authorization_code", "refresh_token"], 20 - response_types: ["code"], 21 - token_endpoint_auth_method: "none", 22 - application_type: "web", 23 - dpop_bound_access_tokens: true, 24 - }; 25 - 26 - const outputPath = `${__dirname}/../public/oauth-client-metadata.json`; 27 - 28 - try { 29 - mkdirSync(dirname(outputPath), { recursive: true }); 30 - writeFileSync(outputPath, JSON.stringify(metadata, null, 2) + "\n"); 31 - console.log(`Generated OAuth metadata for ${baseUrl}`); 32 - } catch (error) { 33 - console.error("Failed to generate OAuth metadata:", error); 34 - process.exit(1); 35 - }
+8
src/components/search.tsx
··· 128 128 129 129 window.addEventListener("paste", handlePaste); 130 130 onCleanup(() => window.removeEventListener("paste", handlePaste)); 131 + 132 + const requestUrl = new URL(location.href); 133 + const requestQuery = requestUrl.searchParams.get("q"); 134 + if (requestQuery != null) { 135 + requestUrl.searchParams.delete("q"); 136 + history.replaceState(null, "", requestUrl.toString()); 137 + processInput(requestQuery); 138 + } 131 139 }); 132 140 133 141 createEffect(() => {

History

1 round 1 comment
sign up or login to add to the discussion
launchpadx.top submitted #0
1 commit
expand
b6921607
feat: opensearch
expand 1 comment

used this PR but made my own changes to fix a few things (tangled doesn't make it easy to reuse PRs atm)

closed without merging