Try to fix ogimage on cloudflare

This commit is contained in:
Samy Pessé
2025-04-07 12:26:20 +02:00
parent d51204148e
commit d06bedbbe1
3 changed files with 15 additions and 2 deletions
+1
View File
@@ -40,6 +40,7 @@ jobs:
run: bun run turbo gitbook#build:cloudflare
env:
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY: ${{ secrets.NEXT_SERVER_ACTIONS_ENCRYPTION_KEY }}
GITBOOK_RUNTIME: cloudflare
- id: deploy
name: Deploy to Cloudflare
uses: cloudflare/wrangler-action@v3.14.0
+1
View File
@@ -5,6 +5,7 @@ module.exports = {
GITBOOK_ICONS_URL: process.env.GITBOOK_ICONS_URL,
GITBOOK_ICONS_TOKEN: process.env.GITBOOK_ICONS_TOKEN,
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY: process.env.NEXT_SERVER_ACTIONS_ENCRYPTION_KEY,
GITBOOK_RUNTIME: process.env.GITBOOK_RUNTIME,
},
webpack(config) {
+13 -2
View File
@@ -8,6 +8,7 @@ import { getFontSourcesToPreload } from '@/fonts/custom';
import { getAssetURL } from '@/lib/assets';
import { filterOutNullable } from '@/lib/typescript';
import type { GitBookSiteContext } from '@v2/lib/context';
import { GITBOOK_RUNTIME } from '@v2/lib/env';
import { getResizedImageURL } from '@v2/lib/images';
const googleFontsMap: { [fontName in CustomizationDefaultFont]: string } = {
@@ -113,8 +114,18 @@ export async function serveOGImage(baseContext: GitBookSiteContext, params: Page
body: baseColors[useLightTheme ? 'dark' : 'light'], // Invert text on background
};
const gridWhite = getAssetURL('images/ogimage-grid-white.png');
const gridBlack = getAssetURL('images/ogimage-grid-black.png');
// For Cloudflare, we use absolute URLs from the root of the site instead
// to avoid issues with worker to worker requests in the same zone.
const gridWhitePath = 'images/ogimage-grid-white.png';
const gridDarkPath = 'images/ogimage-grid-dark.png';
const gridWhite =
GITBOOK_RUNTIME === 'cloudflare'
? linker.toAbsoluteURL(`/~gitbook/static/${gridWhitePath}`)
: getAssetURL(gridWhitePath);
const gridBlack =
GITBOOK_RUNTIME === 'cloudflare'
? linker.toAbsoluteURL(`/~gitbook/static/${gridDarkPath}`)
: getAssetURL(gridDarkPath);
let gridAsset = useLightTheme ? gridBlack : gridWhite;