search: forget 'text', use full url instead
This commit is contained in:
@@ -1,29 +1,9 @@
|
|||||||
import { useEffect, useRef, useState } from "preact/hooks";
|
import { useEffect, useRef, useState } from "preact/hooks";
|
||||||
import { Search } from "lucide-preact";
|
import { Search } from "lucide-preact";
|
||||||
import type { SearchDetail, SearchResultItem } from "@/lib/api";
|
import type { SearchDetail } from "@/lib/api";
|
||||||
import { MarkdownContent } from "@/components/markdown/markdown-content";
|
import { MarkdownContent } from "@/components/markdown/markdown-content";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
function cleanResultText(input: string) {
|
|
||||||
return input
|
|
||||||
.replace(/\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/g, "$1")
|
|
||||||
.replace(/\[\s*\]/g, " ")
|
|
||||||
.replace(/(^|\s)#{1,6}\s*/g, "$1")
|
|
||||||
.replace(/^\s*[-*+]\s+/gm, "")
|
|
||||||
.replace(/(\*\*|__|\*|_|`{1,3}|~~)/g, "")
|
|
||||||
.replace(/\r?\n+/g, " ")
|
|
||||||
.replace(/\s{2,}/g, " ")
|
|
||||||
.trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
function summarizeResult(result: SearchResultItem) {
|
|
||||||
const highlights = Array.isArray(result.highlights) ? result.highlights.filter(Boolean) : [];
|
|
||||||
const raw = highlights.length ? highlights.join(" ") : result.text ?? "";
|
|
||||||
const cleaned = cleanResultText(raw);
|
|
||||||
if (cleaned.length <= 680) return cleaned;
|
|
||||||
return `${cleaned.slice(0, 679).trimEnd()}…`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatHost(url: string) {
|
function formatHost(url: string) {
|
||||||
try {
|
try {
|
||||||
return new URL(url).hostname.replace(/^www\./, "");
|
return new URL(url).hostname.replace(/^www\./, "");
|
||||||
@@ -193,7 +173,6 @@ export function SearchResultsPanel({ search, isLoading, isRunning, showPrompt =
|
|||||||
|
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
{search?.results.map((result) => {
|
{search?.results.map((result) => {
|
||||||
const summary = summarizeResult(result);
|
|
||||||
return (
|
return (
|
||||||
<article key={result.id} className="rounded-lg border border-border bg-[#0d1322] px-4 py-4 shadow-sm">
|
<article key={result.id} className="rounded-lg border border-border bg-[#0d1322] px-4 py-4 shadow-sm">
|
||||||
<p className="text-xs text-emerald-300/85">{formatHost(result.url)}</p>
|
<p className="text-xs text-emerald-300/85">{formatHost(result.url)}</p>
|
||||||
@@ -203,7 +182,7 @@ export function SearchResultsPanel({ search, isLoading, isRunning, showPrompt =
|
|||||||
{(result.publishedDate || result.author) && (
|
{(result.publishedDate || result.author) && (
|
||||||
<p className="mt-1 text-xs text-muted-foreground">{[result.publishedDate, result.author].filter(Boolean).join(" • ")}</p>
|
<p className="mt-1 text-xs text-muted-foreground">{[result.publishedDate, result.author].filter(Boolean).join(" • ")}</p>
|
||||||
)}
|
)}
|
||||||
{summary ? <p className="mt-2 text-sm leading-6 text-slate-200">{summary}</p> : null}
|
{result.url ? <p className="mt-2 text-sm leading-6 text-slate-200">{result.url}</p> : null}
|
||||||
</article>
|
</article>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|||||||
Reference in New Issue
Block a user