@@ -4,11 +4,11 @@ import { render } from "astro:content";
44import JoinUsCTA from " +/components/common/JoinUsCTA.astro" ;
55import ActionButton from " +/components/utils/ActionButton.astro" ;
66import GlobalLayout from " +/layouts/GlobalLayout.astro" ;
7+ import { fetchFavicon } from " +/lib/fetch-favicon" ;
78import { getProjects } from " +/query" ;
89import { Focus } from " +/schema.ts" ;
910import type { GetStaticPaths } from " astro" ;
1011import { Icon } from " astro-icon/components" ;
11- import { load as cheerioLoad } from " cheerio" ;
1212
1313export const getStaticPaths = (async () => {
1414 const projects = await getProjects (" all" );
@@ -22,27 +22,7 @@ const { Content } = await render(project);
2222
2323let iconSrc: string | undefined = undefined ;
2424if (project .data .website && project .data .status !== " dead" ) {
25- const websiteRes = await fetch (project .data .website );
26- if (websiteRes .ok ) {
27- const websiteHtml = await websiteRes .text ();
28- const website = cheerioLoad (websiteHtml );
29- const iconHref = website (" link[rel='icon'], link[rel='shortcut icon']" )[0 ]
30- ?.attribs .href ;
31- if (iconHref ) {
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" )} ` ;
34- } else {
35- const faviconRes = await fetch (
36- ` ${new URL (project .data .website ).origin }/favicon.ico ` ,
37- );
38- if (
39- faviconRes .ok &&
40- ! faviconRes .headers .get (" content-type" )?.startsWith (" text/" )
41- ) {
42- iconSrc = ` data:${faviconRes .headers .get (" content-type" )};base64,${Buffer .from (await faviconRes .arrayBuffer ()).toString (" base64" )} ` ;
43- }
44- }
45- }
25+ iconSrc = await fetchFavicon (project .data .website );
4626}
4727---
4828
0 commit comments