Skip to content

Commit

Permalink
fix(link-card): add fallback url
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Jan 4, 2024
1 parent d212c69 commit f58c9d2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/components/ui/link-card/LinkCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export interface LinkCardProps {
id: string
source?: LinkCardSource
className?: string

fallbackUrl?: string
}

export const LinkCard = (props: LinkCardProps) => {
Expand All @@ -53,11 +55,11 @@ type CardState = {
}

const LinkCardImpl: FC<LinkCardProps> = (props) => {
const { id, source = LinkCardSource.Self, className } = props
const { id, source = LinkCardSource.Self, className, fallbackUrl } = props

const [loading, setLoading] = useState(true)
const [isError, setIsError] = useState(false)
const [fullUrl, setFullUrl] = useState('about:blank')
const [fullUrl, setFullUrl] = useState(fallbackUrl || 'javascript:;')

const [cardInfo, setCardInfo] = useState<CardState>()

Expand Down
19 changes: 16 additions & 3 deletions src/components/ui/markdown/renderers/LinkRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,20 @@ export const BlockLinkRenderer = ({
}
case isSelfArticleUrl(url): {
return (
<LinkCard source={LinkCardSource.Self} id={url.pathname.slice(1)} />
<LinkCard
fallbackUrl={url.toString()}
source={LinkCardSource.Self}
id={url.pathname.slice(1)}
/>
)
}
case isTMDBUrl(url): {
return (
<LinkCard source={LinkCardSource.TMDB} id={url.pathname.slice(1)} />
<LinkCard
fallbackUrl={url.toString()}
source={LinkCardSource.TMDB}
id={url.pathname.slice(1)}
/>
)
}

Expand Down Expand Up @@ -178,7 +186,11 @@ const GithubUrlRenderL: FC<{
case isGithubPrUrl(url): {
const { owner, repo, pr } = parseGithubPrUrl(url)
return (
<LinkCard id={`${owner}/${repo}/${pr}`} source={LinkCardSource.GHPr} />
<LinkCard
fallbackUrl={url.toString()}
id={`${owner}/${repo}/${pr}`}
source={LinkCardSource.GHPr}
/>
)
}

Expand All @@ -190,6 +202,7 @@ const GithubUrlRenderL: FC<{
<MLink href={href}>{href}</MLink>
</p>
<LinkCard
fallbackUrl={url.toString()}
id={`${owner}/${repo}/commit/${id}`}
source={LinkCardSource.GHCommit}
/>
Expand Down

1 comment on commit f58c9d2

@vercel
Copy link

@vercel vercel bot commented on f58c9d2 Jan 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

shiro – ./

springtide.vercel.app
innei.in
shiro-git-main-innei.vercel.app
shiro-innei.vercel.app

Please sign in to comment.