faster banners

This commit is contained in:
tresabhi committed 2026-11-18 23:38:52 -06:00
1 parent a7f0b768a5
commit fc32de0f3f
23 files changed
+67 -4

No files matched your search

@@ -1,4 +1,5 @@
--- ---
import { alias } from "@blitzkit/core";
import { GearIcon } from "@radix-ui/react-icons"; import { GearIcon } from "@radix-ui/react-icons";
import { api } from "../api/dynamic"; import { api } from "../api/dynamic";
import { tools, type Tool } from "../constants/tools"; import { tools, type Tool } from "../constants/tools";
@@ -170,7 +171,10 @@ export const filtered = Object.values(tools).filter(
<LinkI18nWrapper {locale} href={`/${tool.slug ?? tool.id}`}> <LinkI18nWrapper {locale} href={`/${tool.slug ?? tool.id}`}>
<div class="tool"> <div class="tool">
<div <div
style={`background-image: url(/media/tools/banners/${tool.slug ?? tool.id}.webp)`} style={`background-image: url(${alias(
"api",
`/tools/${tool.id}/banners/thumbnail.webp`,
)})`}
class="logo" class="logo"
/> />
@@ -1,4 +1,5 @@
--- ---
import { alias } from "@blitzkit/core";
import { CaretUpIcon, GearIcon } from "@radix-ui/react-icons"; import { CaretUpIcon, GearIcon } from "@radix-ui/react-icons";
import { api } from "../api/dynamic"; import { api } from "../api/dynamic";
import { Logo } from "../icons/Logo"; import { Logo } from "../icons/Logo";
@@ -101,7 +102,7 @@ const strings = await api.strings(locale);
border-radius: var(--radius-max); border-radius: var(--radius-max);
margin-right: var(--space-4); margin-right: var(--space-3);
} }
.icon { .icon {
@@ -209,7 +210,10 @@ const strings = await api.strings(locale);
<LinkI18nWrapper {locale} href={`/${tool.slug ?? tool.id}`}> <LinkI18nWrapper {locale} href={`/${tool.slug ?? tool.id}`}>
<div class="tool"> <div class="tool">
<div <div
style={`background-image: url(/media/tools/banners/${tool.slug ?? tool.id}.webp)`} style={`background-image: url(${alias(
"api",
`/tools/${tool.id}/banners/thumbnail.webp`,
)})`}
class="logo" class="logo"
/> />
@@ -229,7 +233,10 @@ const strings = await api.strings(locale);
<div class="tool" id="current-tool"> <div class="tool" id="current-tool">
<div <div
style={`background-image: url(/media/tools/banners/${tool.slug ?? tool.id}.webp)`} style={`background-image: url(${alias(
"api",
`/tools/${tool.id}/banners/thumbnail.webp`,
)})`}
class="logo" class="logo"
/> />
+10
View File
@@ -93,3 +93,13 @@ export const tools: Record<string, Tool> = {
navbar: false, navbar: false,
}, },
}; };
export enum ToolBannerSize {
Thumbnail = "thumbnail",
Full = "full",
}
export const TOOL_BANNER_HEIGHTS: Record<ToolBannerSize, number | null> = {
[ToolBannerSize.Thumbnail]: 128,
[ToolBannerSize.Full]: null,
};
File renamed without changes.

Before

Width:  |  Height:  |  Size: 170 KiB

After

Width:  |  Height:  |  Size: 170 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 676 KiB

After

Width:  |  Height:  |  Size: 676 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 676 KiB

After

Width:  |  Height:  |  Size: 676 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 187 KiB

After

Width:  |  Height:  |  Size: 187 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 443 KiB

After

Width:  |  Height:  |  Size: 443 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 330 KiB

After

Width:  |  Height:  |  Size: 330 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 166 KiB

After

Width:  |  Height:  |  Size: 166 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 715 KiB

After

Width:  |  Height:  |  Size: 715 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 144 KiB

After

Width:  |  Height:  |  Size: 144 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 188 KiB

After

Width:  |  Height:  |  Size: 188 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 367 KiB

After

Width:  |  Height:  |  Size: 367 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 1.0 MiB

After

Width:  |  Height:  |  Size: 1.0 MiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 274 KiB

After

Width:  |  Height:  |  Size: 274 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 346 KiB

After

Width:  |  Height:  |  Size: 346 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 208 KiB

After

Width:  |  Height:  |  Size: 208 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 406 KiB

After

Width:  |  Height:  |  Size: 406 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 360 KiB

After

Width:  |  Height:  |  Size: 360 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 193 KiB

After

Width:  |  Height:  |  Size: 193 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 200 KiB

After

Width:  |  Height:  |  Size: 200 KiB

@@ -0,0 +1,42 @@
import type { APIContext, GetStaticPathsItem } from "astro";
import { existsSync } from "fs";
import sharp from "sharp";
import { mixStaticPaths } from "../../../../../astro/mixStaticPaths";
import {
TOOL_BANNER_HEIGHTS,
ToolBannerSize,
tools,
} from "../../../../../constants/tools";
import { getStaticPaths as _getStaticPaths } from "../../../_index";
interface ToolBannerProps {
tool: string;
size: ToolBannerSize;
}
function bannerPath(tool: string) {
return `src/media/banners/${tool}.webp`;
}
export const getStaticPaths = mixStaticPaths(_getStaticPaths, () =>
Object.values(tools)
.filter((tool) => existsSync(bannerPath(tool.id)))
.flatMap((tool) =>
Object.values(ToolBannerSize).map(
(size) =>
({
params: { tool: tool.id, size },
props: { tool: tool.id, size } satisfies ToolBannerProps,
} satisfies GetStaticPathsItem),
),
),
);
export async function GET({ props }: APIContext<ToolBannerProps>) {
const height = TOOL_BANNER_HEIGHTS[props.size];
let image = sharp(bannerPath(props.tool));
if (height !== null) image = image.resize({ height });
return new Response(new Uint8Array(await image.webp().toBuffer()));
}