Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
SamyPesse committed Jul 14, 2024
1 parent 3fd8dac commit 3c13792
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 41 deletions.
7 changes: 1 addition & 6 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,5 @@
["style \\=([^;]*);", "\"([^\"]*)\""],
["style \\=([^;]*);", "\\`([^\\`]*)\\`"]
],
"tailwindCSS.classAttributes": [
"class",
"className",
"style",
".*Style"
]
"tailwindCSS.classAttributes": ["class", "className", "style", ".*Style"]
}
18 changes: 15 additions & 3 deletions src/components/DocumentView/BlockContentRef.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ export async function BlockContentRef(props: BlockProps<DocumentBlockContentRef>
);
}

async function SpaceRefCard(props: { resolved: ResolvedContentRef } & BlockProps<DocumentBlockContentRef>) {
async function SpaceRefCard(
props: { resolved: ResolvedContentRef } & BlockProps<DocumentBlockContentRef>,
) {
const { context, style, resolved } = props;
const spaceId = context.contentRefContext?.space.id;

if (!spaceId) { return null; }
if (!spaceId) {
return null;
}

const spaceCustomization = await ignoreAPIError(getSpaceCustomization(spaceId));
const customFavicon = spaceCustomization?.favicon;
Expand All @@ -46,7 +50,15 @@ async function SpaceRefCard(props: { resolved: ResolvedContentRef } & BlockProps

return (
<Card
leadingIcon={<LogoIcon icon={customIcon} emoji={customEmoji} alt='' sizes={[{ width: 24 }]} style={['object-contain', 'size-6']} />}
leadingIcon={
<LogoIcon
icon={customIcon}
emoji={customEmoji}
alt=""
sizes={[{ width: 24 }]}
style={['object-contain', 'size-6']}
/>
}
href={resolved.href}
title={resolved.text}
style={style}
Expand Down
9 changes: 8 additions & 1 deletion src/components/Header/HeaderLogo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,14 @@ function LogoFallback(props: HeaderLogoProps) {
const customEmoji = 'emoji' in customization.favicon ? customization.favicon.emoji : undefined;
return (
<>
<LogoIcon icon={customIcon} emoji={customEmoji} alt='' sizes={[{ width: 32 }]} style={['object-contain', 'size-8']} fetchPriority='high'/>
<LogoIcon
icon={customIcon}
emoji={customEmoji}
alt=""
sizes={[{ width: 32 }]}
style={['object-contain', 'size-8']}
fetchPriority="high"
/>
<h1
className={tcls(
'text-pretty',
Expand Down
66 changes: 38 additions & 28 deletions src/components/icons/LogoIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,49 @@
import { CustomizationThemedURL } from "@gitbook/api";
import { CustomizationThemedURL } from '@gitbook/api';

import { Image } from '@/components/utils';
import { absoluteHref } from "@/lib/links";
import { absoluteHref } from '@/lib/links';

import { Emoji } from "../primitives";
import { Emoji } from '../primitives';


export function LogoIcon(props: { icon?: CustomizationThemedURL; emoji?: string } & Omit<React.ComponentProps<typeof Image>, 'sources'>) {
export function LogoIcon(
props: { icon?: CustomizationThemedURL; emoji?: string } & Omit<
React.ComponentProps<typeof Image>,
'sources'
>,
) {
const { icon, emoji, alt, ...imageProps } = props;

if (emoji && !icon) {
return <Emoji code={emoji} style="text-xl" />;
}

return <Image
alt={alt ?? ''}
sources={icon ? {
light: {
src: icon.light,
aspectRatio: '1',
},
dark: {
src: icon.dark,
aspectRatio: '1',
},
} : {
light: {
src: absoluteHref('~gitbook/icon?size=medium&theme=light', true),
size: { width: 256, height: 256 },
},
dark: {
src: absoluteHref('~gitbook/icon?size=medium&theme=dark', true),
size: { width: 256, height: 256 },
},
}}
{...imageProps}
/>;
return (
<Image
alt={alt ?? ''}
sources={
icon
? {
light: {
src: icon.light,
aspectRatio: '1',
},
dark: {
src: icon.dark,
aspectRatio: '1',
},
}
: {
light: {
src: absoluteHref('~gitbook/icon?size=medium&theme=light', true),
size: { width: 256, height: 256 },
},
dark: {
src: absoluteHref('~gitbook/icon?size=medium&theme=dark', true),
size: { width: 256, height: 256 },
},
}
}
{...imageProps}
/>
);
}
5 changes: 2 additions & 3 deletions src/lib/references.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { getBlockById, getBlockTitle } from './document';
import { gitbookAppHref, pageHref, PageHrefContext } from './links';
import { getPagePath, resolvePageId } from './pages';


export interface ResolvedContentRef {
/** Text to render in the content ref */
text: string;
Expand Down Expand Up @@ -165,7 +164,7 @@ export async function resolveContentRef(
contentRef.space === space.id
? space
: await ignoreAPIError(getSpace(contentRef.space));

if (!targetSpace) {
return {
href: gitbookAppHref(`/s/${contentRef.space}`),
Expand All @@ -177,7 +176,7 @@ export async function resolveContentRef(
return {
href: targetSpace.urls.published ?? targetSpace.urls.app,
text: targetSpace.title,
active: true
active: true,
};
}

Expand Down

0 comments on commit 3c13792

Please sign in to comment.