Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bun.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"astro": "^5.7.12",
"astro-icon": "^1.1.5",
"bits-ui": "^1.4.8",
"cheerio": "^1.0.0",
"daisyui": "^5.0.35",
"date-fns": "^4.1.0",
"markdown-to-txt": "^2.0.1",
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"astro": "^5.7.12",
"astro-icon": "^1.1.5",
"bits-ui": "^1.4.8",
"cheerio": "^1.0.0",
"daisyui": "^5.0.35",
"date-fns": "^4.1.0",
"markdown-to-txt": "^2.0.1",
Expand Down
32 changes: 31 additions & 1 deletion src/pages/projects/[...id].astro
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { getProjects } from "+/query";
import { Focus } from "+/schema.ts";
import type { GetStaticPaths } from "astro";
import { Icon } from "astro-icon/components";
import { load as cheerioLoad } from "cheerio";

export const getStaticPaths = (async () => {
const projects = await getProjects("all");
Expand All @@ -18,6 +19,31 @@ export const getStaticPaths = (async () => {
}) satisfies GetStaticPaths;
const { project } = Astro.props;
const { Content } = await render(project);

let iconSrc: string | undefined = undefined;
if (project.data.website && project.data.status !== "dead") {
const websiteRes = await fetch(project.data.website);
if (websiteRes.ok) {
const websiteHtml = await websiteRes.text();
const website = cheerioLoad(websiteHtml);
const iconHref = website("link[rel='icon'], link[rel='shortcut icon']")[0]
?.attribs.href;
if (iconHref) {
const faviconRes = await fetch(new URL(iconHref, project.data.website));
iconSrc = `data:${faviconRes.headers.get("content-type")};base64,${Buffer.from(await faviconRes.arrayBuffer()).toString("base64")}`;
} else {
const faviconRes = await fetch(
`${new URL(project.data.website).origin}/favicon.ico`,
);
if (
faviconRes.ok &&
!faviconRes.headers.get("content-type")?.startsWith("text/")
) {
iconSrc = `data:${faviconRes.headers.get("content-type")};base64,${Buffer.from(await faviconRes.arrayBuffer()).toString("base64")}`;
}
}
}
}
---

<GlobalLayout
Expand Down Expand Up @@ -95,7 +121,11 @@ const { Content } = await render(project);
{
project.data.website && project.data.status !== "dead" && (
<ActionButton to={project.data.website} class="my-6">
<Icon name="feather:globe" class="mr-2 inline-block h-6 w-6" />
{iconSrc ? (
<img src={iconSrc} alt="favicon" class="inline-block h-6 w-6" />
) : (
<Icon name="feather:globe" class="inline-block h-6 w-6" />
)}
{project.data.title} へ
</ActionButton>
)
Expand Down