e7d349bc30
Task 8: codemod repointed 150 namespace-type files to #/lexicons (AppBskyFeedDefs.PostView -> app.bsky.feed.defs.PostView, .Record -> .Main) plus ~105 hand-fixed consumers (composer/video state, DebugMod, Profile, onboarding, dialogs). DM_SERVICE_HEADERS deleted; last chat call sites on the chat client. RichText.tsx flipped to SDK-only. Remaining @atproto/api importers: the three session bridge files, the deliberate dual-world matcher in lib/xrpc-error.ts, and test fixtures. toLex boundary casts are TODO(phase4)-tagged for bridge removal. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
import {Leaflet} from '#/components/icons/community/Leaflet'
|
|
import {Offprint} from '#/components/icons/community/Offprint'
|
|
import {Pckt} from '#/components/icons/community/Pckt'
|
|
import {type app} from '#/lexicons'
|
|
|
|
export type StandardSitePublisher = {
|
|
host: string
|
|
name: string
|
|
Icon: typeof Leaflet
|
|
}
|
|
|
|
const STANDARD_SITE_PUBLISHERS: StandardSitePublisher[] = [
|
|
{host: 'leaflet.pub', name: 'Leaflet', Icon: Leaflet},
|
|
{host: 'pckt.blog', name: 'pckt', Icon: Pckt},
|
|
{host: 'offprint.app', name: 'Offprint', Icon: Offprint},
|
|
]
|
|
|
|
function hostFromUri(uri: string | undefined): string | null {
|
|
try {
|
|
return new URL(uri || '').host
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|
|
|
|
export function getStandardSitePublisherHost(
|
|
view: app.bsky.embed.external.ViewExternal,
|
|
): string | null {
|
|
return hostFromUri(view.source?.uri)
|
|
}
|
|
|
|
export function hostMatches(host: string, target: string): boolean {
|
|
return host === target || host.endsWith('.' + target)
|
|
}
|
|
|
|
function matchByHost(host: string | null): StandardSitePublisher | null {
|
|
if (!host) return null
|
|
return STANDARD_SITE_PUBLISHERS.find(p => hostMatches(host, p.host)) ?? null
|
|
}
|
|
|
|
export function matchStandardSitePublisher(
|
|
view: app.bsky.embed.external.ViewExternal,
|
|
): StandardSitePublisher | null {
|
|
return matchByHost(getStandardSitePublisherHost(view))
|
|
}
|
|
|
|
export function matchStandardSitePublisherByUri(
|
|
uri: string | undefined,
|
|
): StandardSitePublisher | null {
|
|
return matchByHost(hostFromUri(uri))
|
|
}
|