[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:
@@ -8,7 +8,10 @@ import {toNiceDomain} from '#/lib/strings/url-helpers'
|
|||||||
import {atoms as a, useTheme} from '#/alf'
|
import {atoms as a, useTheme} from '#/alf'
|
||||||
import {StandardSite} from '#/components/icons/community/StandardSite'
|
import {StandardSite} from '#/components/icons/community/StandardSite'
|
||||||
import {InlineLinkText} from '#/components/Link'
|
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 {isStandardSiteDocumentUri} from '#/components/Post/Embed/StandardSiteEmbed/utils'
|
||||||
import {Text} from '#/components/Typography'
|
import {Text} from '#/components/Typography'
|
||||||
|
|
||||||
@@ -34,6 +37,8 @@ export function PublicationMetaRow({
|
|||||||
? view.associatedProfiles?.find(p => p.did === authorDid)
|
? view.associatedProfiles?.find(p => p.did === authorDid)
|
||||||
: undefined
|
: undefined
|
||||||
const articleDomain = toNiceDomain(view.uri)
|
const articleDomain = toNiceDomain(view.uri)
|
||||||
|
const articlePublisher = matchStandardSitePublisherByUri(view.uri)
|
||||||
|
const DomainIcon = articlePublisher?.Icon ?? StandardSite
|
||||||
const metaTextStyle = [
|
const metaTextStyle = [
|
||||||
a.text_xs,
|
a.text_xs,
|
||||||
a.leading_snug,
|
a.leading_snug,
|
||||||
@@ -47,7 +52,7 @@ export function PublicationMetaRow({
|
|||||||
key: 'domain',
|
key: 'domain',
|
||||||
node: (
|
node: (
|
||||||
<View style={[a.flex_row, a.align_center]}>
|
<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}>
|
<Text numberOfLines={1} style={metaTextStyle}>
|
||||||
{articleDomain}
|
{articleDomain}
|
||||||
</Text>
|
</Text>
|
||||||
|
|||||||
@@ -16,24 +16,37 @@ const STANDARD_SITE_PUBLISHERS: StandardSitePublisher[] = [
|
|||||||
{host: 'offprint.app', name: 'Offprint', Icon: Offprint},
|
{host: 'offprint.app', name: 'Offprint', Icon: Offprint},
|
||||||
]
|
]
|
||||||
|
|
||||||
export function getStandardSitePublisherHost(
|
function hostFromUri(uri: string | undefined): string | null {
|
||||||
view: AppBskyEmbedExternal.ViewExternal,
|
|
||||||
): string | null {
|
|
||||||
try {
|
try {
|
||||||
return new URL(view.source?.uri || '').host
|
return new URL(uri || '').host
|
||||||
} catch {
|
} catch {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getStandardSitePublisherHost(
|
||||||
|
view: AppBskyEmbedExternal.ViewExternal,
|
||||||
|
): string | null {
|
||||||
|
return hostFromUri(view.source?.uri)
|
||||||
|
}
|
||||||
|
|
||||||
export function hostMatches(host: string, target: string): boolean {
|
export function hostMatches(host: string, target: string): boolean {
|
||||||
return host === target || host.endsWith('.' + target)
|
return host === target || host.endsWith('.' + target)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function matchStandardSitePublisher(
|
function matchByHost(host: string | null): StandardSitePublisher | null {
|
||||||
view: AppBskyEmbedExternal.ViewExternal,
|
|
||||||
): StandardSitePublisher | null {
|
|
||||||
const host = getStandardSitePublisherHost(view)
|
|
||||||
if (!host) return null
|
if (!host) return null
|
||||||
return STANDARD_SITE_PUBLISHERS.find(p => hostMatches(host, p.host)) ?? 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))
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user