Page MenuHomePhorge

rehype-images.ts
No OneTemporary

Authored By
Unknown
Size
695 B
Referenced Files
None
Subscribers
None

rehype-images.ts

import type { Element, Root } from "npm:@types/hast";
import type { VFile } from "vfile";
import { visit } from "unist-util-visit";
import { join } from "@std/path";
import { asset } from "#/assets.ts";
export default function rehypeImages() {
return async function (tree: Root, file: VFile) {
const images: Element[] = [];
visit(tree, "element", function (node) {
if (node.tagName === "img") {
images.push(node);
}
});
for (const node of images) {
node.properties.src = await asset(
join(
"#src",
"articles",
file.data.slug as string,
node.properties.src as string,
),
);
}
};
}

File Metadata

Mime Type
application/javascript
Expires
Sun, Oct 25, 04:27 (1 d, 2 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
58
Default Alt Text
rehype-images.ts (695 B)

Event Timeline