main
 1import type { RehypePlugin } from "@astrojs/markdown-remark";
 2import { visit } from "unist-util-visit";
 3import { SITE_CONFIG } from "@/config.js";
 4import { extractImage } from "@/integrations/extract-image.js";
 5import { url } from "@/utils/url.js";
 6import { getBase64ImageInfo } from "../utils/image.js";
 7
 8export const rehypeExtractImage: RehypePlugin = () => (tree) => {
 9  visit(tree, "element", (node) => {
10    if (node.tagName === "img") {
11      const src = node.properties?.src;
12      if (typeof src === "string") {
13        const imageInfo = getBase64ImageInfo(src);
14        if (imageInfo) {
15          node.properties.src = url(
16            `/${extractImage({ dir: SITE_CONFIG.assetDir }).api.dir}/${imageInfo.filename}`,
17          );
18        }
19      }
20    }
21  });
22};