diff options
Diffstat (limited to 'castle-search/src/extract.ts')
| -rw-r--r-- | castle-search/src/extract.ts | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/castle-search/src/extract.ts b/castle-search/src/extract.ts index 8b5c57f..653942b 100644 --- a/castle-search/src/extract.ts +++ b/castle-search/src/extract.ts @@ -35,7 +35,9 @@ * - DuckDuckGo: `//duckduckgo.com/l/?uddg=<percent-encoded target>` * - Bing: `//bing.com/ck/a?…&u=a1<base64url of target>` * - * Google and Brave link straight out and need no unwrapping. + * Brave links straight out. Google wraps results in `/goto?url=<opaque token>` + * that only Google can resolve; those are left alone here and resolved + * node-side by resolve.ts. */ import type { ExtractionConfig } from "./engines.ts"; @@ -45,6 +47,8 @@ export type SearchResult = { title: string; url: string; snippet: string; + /** Google only: the site and breadcrumb as displayed, kept for links that cannot be resolved. */ + display?: string; }; /** What the page script returns in a single round trip. */ @@ -261,8 +265,13 @@ export const buildProbeScript = (config: ExtractionConfig): string => String.raw ).replace(/Read more$/, "").trim(); } + var display = ""; + var siteEl = anchor.querySelector("span.VuuXrf"); + var citeEl = anchor.querySelector("cite"); + display = norm([siteEl && siteEl.innerText, citeEl && citeEl.innerText].filter(Boolean).join(" — ")); + seen[url] = true; - out.push({ title: title, url: url, snippet: snippet.slice(0, 600) }); + out.push({ title: title, url: url, snippet: snippet.slice(0, 600), display: display }); } return out; }; |
