mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-21 18:55:16 +02:00
fix(web): extract single tryGetHostname helper (DRY, unified fallback)
Fixes #1368 Previously, was duplicated in 4 places with 3 subtly different fallback behaviors: 1. inline-citation.tsx: returned on error 2. markdown-text.tsx: returned on error 3. assistant-message.tsx: returned on error 4. citation.tsx: returned on error Created canonical in that: - Returns - Strips prefix from hostname - Returns on invalid URL (safest contract) Updated all 4 call sites: - inline-citation.tsx: (preserves original fallback) - markdown-text.tsx: (preserves original fallback) - assistant-message.tsx: (drop-in, both return ) - citation.tsx: (drop-in, both return ) Co-authored-by: guangyang1206 <guangyang1206@users.noreply.github.com>
This commit is contained in:
parent
1119f557df
commit
f096548a16
5 changed files with 24 additions and 38 deletions
|
|
@ -193,14 +193,7 @@ const SurfsenseDocCitation: FC<{ chunkId: number }> = ({ chunkId }) => {
|
|||
);
|
||||
};
|
||||
|
||||
function extractDomain(url: string): string {
|
||||
try {
|
||||
const hostname = new URL(url).hostname;
|
||||
return hostname.replace(/^www\./, "");
|
||||
} catch {
|
||||
return url;
|
||||
}
|
||||
}
|
||||
import { tryGetHostname } from "@/lib/url";
|
||||
|
||||
interface UrlCitationProps {
|
||||
url: string;
|
||||
|
|
@ -212,7 +205,7 @@ interface UrlCitationProps {
|
|||
* page title and snippet (extracted deterministically from web_search tool results).
|
||||
*/
|
||||
export const UrlCitation: FC<UrlCitationProps> = ({ url }) => {
|
||||
const domain = extractDomain(url);
|
||||
const domain = tryGetHostname(url) ?? url;
|
||||
const meta = useCitationMetadata(url);
|
||||
|
||||
return (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue