Skip to content

Commit d512041

Browse files
authored
Revert debugging of ogimage errors (#3105)
1 parent 319761a commit d512041

File tree

6 files changed

+17
-164
lines changed

6 files changed

+17
-164
lines changed

bun.lock

+10-53
Large diffs are not rendered by default.

packages/gitbook-v2/src/lib/links.ts

+1-12
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,6 @@ export function createLinker(
7272

7373
const siteBasePath = withTrailingSlash(withLeadingSlash(servedOn.siteBasePath));
7474
const spaceBasePath = withTrailingSlash(withLeadingSlash(servedOn.spaceBasePath));
75-
const protocol = (() => {
76-
if (servedOn.protocol) {
77-
return servedOn.protocol;
78-
}
79-
80-
if (servedOn.host) {
81-
return servedOn.host.startsWith('localhost') ? 'http:' : 'https:';
82-
}
83-
84-
return 'https:';
85-
})();
8675

8776
const linker: GitBookLinker = {
8877
toPathInSpace(relativePath: string): string {
@@ -108,7 +97,7 @@ export function createLinker(
10897
return absolutePath;
10998
}
11099

111-
return `${protocol}//${joinPaths(servedOn.host, absolutePath)}`;
100+
return `${servedOn.protocol ?? 'https:'}//${joinPaths(servedOn.host, absolutePath)}`;
112101
},
113102

114103
toPathForPage({ pages, page, anchor }) {

packages/gitbook/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
"@sindresorhus/fnv1a": "^3.1.0",
3434
"@tailwindcss/container-queries": "^0.1.1",
3535
"@tailwindcss/typography": "^0.5.16",
36-
"@vercel/og": "0.6.8.",
3736
"ai": "^4.2.2",
3837
"assert-never": "^1.2.1",
3938
"bun-types": "^1.1.20",
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,14 @@
1-
import { ImageResponse } from '@vercel/og';
2-
import { notFound, redirect } from 'next/navigation';
31
import type { NextRequest } from 'next/server';
42

5-
import { getEmojiForCode } from '@/lib/emojis';
63
import { getSiteContentPointer } from '@/lib/pointer';
7-
import { tcls } from '@/lib/tailwind';
84
import { fetchV1ContextForSitePointer } from '@/lib/v1';
9-
import { getResizedImageURL } from '@v2/lib/images';
5+
import { serveIcon } from '@/routes/icon';
106

117
export const runtime = 'edge';
128

13-
const SIZES = {
14-
/** Size for a favicon */
15-
small: {
16-
width: 48,
17-
height: 48,
18-
textSize: 'text-[32px]',
19-
boxStyle: 'rounded-[8px]',
20-
},
21-
/** Size for display as an app icon or in the header */
22-
medium: {
23-
width: 256,
24-
height: 256,
25-
textSize: 'text-[164px]',
26-
boxStyle: 'rounded-[32px]',
27-
},
28-
};
29-
30-
/**
31-
* Generate an icon for a site content.
32-
*/
339
export async function GET(req: NextRequest) {
34-
const options = getOptions(req.url);
3510
const pointer = await getSiteContentPointer();
3611
const context = await fetchV1ContextForSitePointer(pointer);
3712

38-
const size = SIZES[options.size];
39-
const { site, customization } = context;
40-
const customIcon = 'icon' in customization.favicon ? customization.favicon.icon : null;
41-
42-
// If the site has a custom icon, redirect to it
43-
if (customIcon) {
44-
const iconUrl = options.theme === 'light' ? customIcon.light : customIcon.dark;
45-
redirect(
46-
await getResizedImageURL(context.imageResizer, iconUrl, {
47-
width: size.width,
48-
height: size.height,
49-
})
50-
);
51-
}
52-
53-
const contentTitle = site.title;
54-
return new ImageResponse(
55-
<div
56-
tw={tcls(options.theme === 'light' ? 'bg-white' : 'bg-black', size.boxStyle)}
57-
style={{
58-
width: '100%',
59-
height: '100%',
60-
display: 'flex',
61-
alignItems: 'center',
62-
justifyContent: 'center',
63-
}}
64-
>
65-
<h2
66-
tw={tcls(
67-
size.textSize,
68-
'font-bold',
69-
'tracking-tight',
70-
options.theme === 'light' ? 'text-black' : 'text-white'
71-
)}
72-
>
73-
{'emoji' in customization.favicon
74-
? getEmojiForCode(customization.favicon.emoji)
75-
: contentTitle.slice(0, 1).toUpperCase()}
76-
</h2>
77-
</div>,
78-
{
79-
width: size.width,
80-
height: size.height,
81-
}
82-
);
83-
}
84-
85-
function getOptions(inputUrl: string): {
86-
size: keyof typeof SIZES;
87-
theme: 'light' | 'dark';
88-
} {
89-
const url = new URL(inputUrl);
90-
const sizeParam = (url.searchParams.get('size') ?? 'small') as keyof typeof SIZES;
91-
const themeParam = url.searchParams.get('theme') ?? 'light';
92-
93-
if (!SIZES[sizeParam] || !['light', 'dark'].includes(themeParam)) {
94-
notFound();
95-
}
96-
97-
return {
98-
// @ts-ignore
99-
size: sizeParam,
100-
// @ts-ignore
101-
theme: themeParam,
102-
};
13+
return serveIcon(context, req);
10314
}

packages/gitbook/src/lib/cache/cloudflare-do.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,7 @@ export const cloudflareDOCache: CacheBackend = {
2626
return null;
2727
}
2828

29-
try {
30-
return (await stub.get<CacheEntry>(key)) ?? null;
31-
} catch (err) {
32-
console.error('cloudflareDO.get', err);
33-
return null;
34-
}
29+
return (await stub.get<CacheEntry>(key)) ?? null;
3530
}
3631
);
3732
},

packages/gitbook/src/routes/icon.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { ImageResponse } from '@vercel/og';
21
import { notFound, redirect } from 'next/navigation';
2+
import { ImageResponse } from 'next/og';
33

44
import { getEmojiForCode } from '@/lib/emojis';
55
import { tcls } from '@/lib/tailwind';
@@ -32,6 +32,7 @@ export async function serveIcon(context: GitBookSiteContext, req: Request) {
3232

3333
const { site, customization } = context;
3434
const customIcon = 'icon' in customization.favicon ? customization.favicon.icon : null;
35+
3536
// If the site has a custom icon, redirect to it
3637
if (customIcon) {
3738
const iconUrl = options.theme === 'light' ? customIcon.light : customIcon.dark;
@@ -44,6 +45,7 @@ export async function serveIcon(context: GitBookSiteContext, req: Request) {
4445
}
4546

4647
const contentTitle = site.title;
48+
4749
return new ImageResponse(
4850
<div
4951
tw={tcls(options.theme === 'light' ? 'bg-white' : 'bg-black', size.boxStyle)}

0 commit comments

Comments
 (0)