merge in new changes
This commit is contained in:
24
src/pages/favicon.ico.ts
Normal file
24
src/pages/favicon.ico.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import path from 'node:path';
|
||||
import type { APIRoute } from 'astro';
|
||||
import sharp from 'sharp';
|
||||
import ico from 'sharp-ico';
|
||||
|
||||
const faviconSrc = path.resolve('src/images/favicon_icon.png');
|
||||
|
||||
export const GET: APIRoute = async () => {
|
||||
// Resize the image to multiple sizes
|
||||
const sizes = [16, 32];
|
||||
|
||||
const buffers = await Promise.all(
|
||||
sizes.map(async (size) => {
|
||||
return await sharp(faviconSrc).resize(size).toFormat('png').toBuffer();
|
||||
})
|
||||
);
|
||||
|
||||
// Convert the image to an ICO file
|
||||
const icoBuffer = ico.encode(buffers);
|
||||
|
||||
return new Response(icoBuffer, {
|
||||
headers: { 'Content-Type': 'image/x-icon' },
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user