Unverified Commit 47f14a84 authored by Hong Minhee's avatar Hong Minhee
Browse files

Support for ICO format in favicon rendering

parent 9c01da8d
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -93,6 +93,7 @@
    "hono",
    "httpsig",
    "hugoalh",
    "icojs",
    "instanceof",
    "interoperating",
    "jsonld",
@@ -143,6 +144,7 @@
    "urlpattern",
    "uuidv7",
    "vitepress",
    "webfinger"
    "webfinger",
    "webp"
  ]
}
+3 −0
Original line number Diff line number Diff line
@@ -8,6 +8,9 @@ Version 1.2.1

To be released.

 -  Now `fedify node` command can render the node's favicon with
    `image/vnd.microsoft.icon` or `image/x-icon` format.


Version 1.2.0
-------------
+1 −0
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@
    "cli-highlight": "npm:cli-highlight@^2.1.11",
    "hono": "jsr:@hono/hono@^4.5.9",
    "hono/": "jsr:/@hono/hono@^4.5.9/",
    "icojs": "npm:icojs@^0.19.4",
    "jimp": "npm:jimp@^1.6.0",
    "json-preserve-indent": "npm:json-preserve-indent@^1.1.3",
    "ora": "npm:ora@^8.0.1",
+1 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
    "cli-highlight": "npm:cli-highlight@^2.1.11",
    "hono": "jsr:@hono/hono@^4.5.9",
    "hono/": "jsr:/@hono/hono@^4.5.9/",
    "icojs": "npm:icojs@^0.19.4",
    "jimp": "npm:jimp@^1.6.0",
    "json-preserve-indent": "npm:json-preserve-indent@^1.1.3",
    "ora": "npm:ora@^8.0.1",
+31 −4
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ import { formatSemVer, getNodeInfo } from "@fedify/fedify";
import { createJimp } from "@jimp/core";
import webp from "@jimp/wasm-webp";
import { getLogger } from "@logtape/logtape";
import { isICO, parseICO } from "icojs";
import { defaultFormats, defaultPlugins, intToRGBA } from "jimp";
import ora from "ora";
import { printJson } from "./utils.ts";
@@ -70,10 +71,36 @@ export const command = new Command()
      spinner.text = "Fetching the favicon...";
      try {
        const faviconUrl = await getFaviconUrl(url);
        const image = await Jimp.read(faviconUrl.href);
        const response = await fetch(faviconUrl);
        if (response.ok) {
          const contentType = response.headers.get("Content-Type");
          let buffer: ArrayBuffer = await response.arrayBuffer();
          if (
            contentType === "image/vnd.microsoft.icon" ||
            contentType === "image/x-icon" ||
            isICO(buffer)
          ) {
            const images = await parseICO(buffer);
            if (images.length < 1) {
              throw new Error("No images found in the ICO file.");
            }
            buffer = images[0].buffer;
          }
          const image = await Jimp.read(buffer);
          layout = getAsciiArt(image).split("\n").map((line) => ` ${line}  `);
          defaultWidth = 41;
      } catch {
        } else {
          logger.error(
            "Failed to fetch the favicon: {status} {statusText}",
            { status: response.status, statusText: response.statusText },
          );
          layout = [""];
        }
      } catch (error) {
        logger.error(
          "Failed to fetch or render the favicon: {error}",
          { error },
        );
        layout = [""];
      }
    } else {