[APP-2160] Use publisher icon for known hosts in PublicationMetaRow

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Eric Bailey
2026-05-22 17:04:45 -05:00
parent f79453d87d
commit c4c679446c
2 changed files with 28 additions and 10 deletions
@@ -8,7 +8,10 @@ import {toNiceDomain} from '#/lib/strings/url-helpers'
import {atoms as a, useTheme} from '#/alf'
import {StandardSite} from '#/components/icons/community/StandardSite'
import {InlineLinkText} from '#/components/Link'
import {matchStandardSitePublisher} from '#/components/Post/Embed/StandardSiteEmbed/publishers'
import {
matchStandardSitePublisher,
matchStandardSitePublisherByUri,
} from '#/components/Post/Embed/StandardSiteEmbed/publishers'
import {isStandardSiteDocumentUri} from '#/components/Post/Embed/StandardSiteEmbed/utils'
import {Text} from '#/components/Typography'
@@ -34,6 +37,8 @@ export function PublicationMetaRow({
? view.associatedProfiles?.find(p => p.did === authorDid)
: undefined
const articleDomain = toNiceDomain(view.uri)
const articlePublisher = matchStandardSitePublisherByUri(view.uri)
const DomainIcon = articlePublisher?.Icon ?? StandardSite
const metaTextStyle = [
a.text_xs,
a.leading_snug,
@@ -47,7 +52,7 @@ export function PublicationMetaRow({
key: 'domain',
node: (
<View style={[a.flex_row, a.align_center]}>
<StandardSite size="sm" fill={t.atoms.text_contrast_medium.color} />
<DomainIcon size="sm" fill={t.atoms.text_contrast_medium.color} />
<Text numberOfLines={1} style={metaTextStyle}>
{articleDomain}
</Text>
@@ -16,24 +16,37 @@ const STANDARD_SITE_PUBLISHERS: StandardSitePublisher[] = [
{host: 'offprint.app', name: 'Offprint', Icon: Offprint},
]
export function getStandardSitePublisherHost(
view: AppBskyEmbedExternal.ViewExternal,
): string | null {
function hostFromUri(uri: string | undefined): string | null {
try {
return new URL(view.source?.uri || '').host
return new URL(uri || '').host
} catch {
return null
}
}
export function getStandardSitePublisherHost(
view: AppBskyEmbedExternal.ViewExternal,
): string | null {
return hostFromUri(view.source?.uri)
}
export function hostMatches(host: string, target: string): boolean {
return host === target || host.endsWith('.' + target)
}
export function matchStandardSitePublisher(
view: AppBskyEmbedExternal.ViewExternal,
): StandardSitePublisher | null {
const host = getStandardSitePublisherHost(view)
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: AppBskyEmbedExternal.ViewExternal,
): StandardSitePublisher | null {
return matchByHost(getStandardSitePublisherHost(view))
}
export function matchStandardSitePublisherByUri(
uri: string | undefined,
): StandardSitePublisher | null {
return matchByHost(hostFromUri(uri))
}