Files
popov.link/src/plugins/rehypeLazyImages.ts
T

14 lines
367 B
TypeScript
Raw Normal View History

import type { Element, Root } from "hast";
import { visit } from "unist-util-visit";
export default function rehypeLazyImages() {
return (tree: Root): void => {
visit(tree, "element", (node: Element) => {
if (node.tagName !== "img") return;
node.properties ??= {};
node.properties.loading ??= "lazy";
node.properties.decoding ??= "async";
});
};
}