faster banners
No files matched your search
@@ -1,4 +1,5 @@
|
||||
---
|
||||
import { alias } from "@blitzkit/core";
|
||||
import { GearIcon } from "@radix-ui/react-icons";
|
||||
import { api } from "../api/dynamic";
|
||||
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}`}>
|
||||
<div class="tool">
|
||||
<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"
|
||||
/>
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
---
|
||||
import { alias } from "@blitzkit/core";
|
||||
import { CaretUpIcon, GearIcon } from "@radix-ui/react-icons";
|
||||
import { api } from "../api/dynamic";
|
||||
import { Logo } from "../icons/Logo";
|
||||
@@ -101,7 +102,7 @@ const strings = await api.strings(locale);
|
||||
|
||||
border-radius: var(--radius-max);
|
||||
|
||||
margin-right: var(--space-4);
|
||||
margin-right: var(--space-3);
|
||||
}
|
||||
|
||||
.icon {
|
||||
@@ -209,7 +210,10 @@ const strings = await api.strings(locale);
|
||||
<LinkI18nWrapper {locale} href={`/${tool.slug ?? tool.id}`}>
|
||||
<div class="tool">
|
||||
<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"
|
||||
/>
|
||||
|
||||
@@ -229,7 +233,10 @@ const strings = await api.strings(locale);
|
||||
|
||||
<div class="tool" id="current-tool">
|
||||
<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"
|
||||
/>
|
||||
|
||||
|
||||
@@ -93,3 +93,13 @@ export const tools: Record<string, Tool> = {
|
||||
navbar: false,
|
||||
},
|
||||
};
|
||||
|
||||
export enum ToolBannerSize {
|
||||
Thumbnail = "thumbnail",
|
||||
Full = "full",
|
||||
}
|
||||
|
||||
export const TOOL_BANNER_HEIGHTS: Record<ToolBannerSize, number | null> = {
|
||||
[ToolBannerSize.Thumbnail]: 128,
|
||||
[ToolBannerSize.Full]: null,
|
||||
};
|
||||
|
Before Width: | Height: | Size: 170 KiB After Width: | Height: | Size: 170 KiB |
|
Before Width: | Height: | Size: 676 KiB After Width: | Height: | Size: 676 KiB |
|
Before Width: | Height: | Size: 676 KiB After Width: | Height: | Size: 676 KiB |
|
Before Width: | Height: | Size: 187 KiB After Width: | Height: | Size: 187 KiB |
|
Before Width: | Height: | Size: 443 KiB After Width: | Height: | Size: 443 KiB |
|
Before Width: | Height: | Size: 330 KiB After Width: | Height: | Size: 330 KiB |
|
Before Width: | Height: | Size: 166 KiB After Width: | Height: | Size: 166 KiB |
|
Before Width: | Height: | Size: 715 KiB After Width: | Height: | Size: 715 KiB |
|
Before Width: | Height: | Size: 144 KiB After Width: | Height: | Size: 144 KiB |
|
Before Width: | Height: | Size: 188 KiB After Width: | Height: | Size: 188 KiB |
|
Before Width: | Height: | Size: 367 KiB After Width: | Height: | Size: 367 KiB |
|
Before Width: | Height: | Size: 1.0 MiB After Width: | Height: | Size: 1.0 MiB |
|
Before Width: | Height: | Size: 274 KiB After Width: | Height: | Size: 274 KiB |
|
Before Width: | Height: | Size: 346 KiB After Width: | Height: | Size: 346 KiB |
|
Before Width: | Height: | Size: 208 KiB After Width: | Height: | Size: 208 KiB |
|
Before Width: | Height: | Size: 406 KiB After Width: | Height: | Size: 406 KiB |
|
Before Width: | Height: | Size: 360 KiB After Width: | Height: | Size: 360 KiB |
|
Before Width: | Height: | Size: 193 KiB After Width: | Height: | Size: 193 KiB |
|
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()));
|
||||
}
|
||||