Skip to content

Commit

Permalink
Add fallback prop to note favicon
Browse files Browse the repository at this point in the history
  • Loading branch information
colebemis committed Oct 3, 2023
1 parent 1507ae4 commit 2dd288e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/components/markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,11 @@ function NoteLink({ id, text }: NoteLinkProps) {
<HoverCard.Trigger asChild>
<Link ref={ref} target="_blank" to={`/${id}`}>
{isFirst && note ? (
<NoteFavicon note={note} className="mr-2 align-sub [h1>a>&]:align-baseline" />
<NoteFavicon
note={note}
className="mr-2 align-sub [h1>a>&]:align-baseline"
fallback={null}
/>
) : null}
{text}
</Link>
Expand Down
14 changes: 12 additions & 2 deletions src/components/note-favicon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ import { WebsiteFavicon } from "./website-favicon"

type NoteFaviconProps = React.ComponentPropsWithoutRef<"span"> & {
note: Note
fallback?: React.ReactNode
}

export function NoteFavicon({ note, className, ...props }: NoteFaviconProps) {
let icon = <NoteIcon16 data-testid="favicon-default" />
export function NoteFavicon({
note,
className,
fallback = <NoteIcon16 data-testid="favicon-default" />,
...props
}: NoteFaviconProps) {
let icon = fallback

// GitHub
if (typeof note.frontmatter.github === "string") {
Expand Down Expand Up @@ -46,6 +52,10 @@ export function NoteFavicon({ note, className, ...props }: NoteFaviconProps) {
icon = <NoteTemplateIcon16 data-testid="favicon-template" />
}

if (!icon) {
return null
}

return (
<span
className={cx("inline-grid h-4 w-4 place-items-center text-text-secondary", className)}
Expand Down

0 comments on commit 2dd288e

Please sign in to comment.