Skip to content

Commit 665b15d

Browse files
committed
base64で埋め込んだほうが速い
1 parent 7df5ef8 commit 665b15d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/pages/projects/[...id].astro

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ if (project.data.website && project.data.status !== "dead") {
2929
const iconHref = website("link[rel='icon'], link[rel='shortcut icon']")[0]
3030
?.attribs.href;
3131
if (iconHref) {
32-
iconSrc = new URL(iconHref, project.data.website).toString();
32+
const faviconRes = await fetch(new URL(iconHref, project.data.website));
33+
iconSrc = `data:${faviconRes.headers.get("content-type")};base64,${Buffer.from(await faviconRes.arrayBuffer()).toString("base64")}`;
3334
} else {
3435
const faviconRes = await fetch(
3536
`${new URL(project.data.website).origin}/favicon.ico`,
@@ -38,7 +39,7 @@ if (project.data.website && project.data.status !== "dead") {
3839
faviconRes.ok &&
3940
!faviconRes.headers.get("content-type")?.startsWith("text/")
4041
) {
41-
iconSrc = faviconRes.url;
42+
iconSrc = `data:${faviconRes.headers.get("content-type")};base64,${Buffer.from(await faviconRes.arrayBuffer()).toString("base64")}`;
4243
}
4344
}
4445
}

0 commit comments

Comments
 (0)