aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/rehypeLazyImages.ts
blob: eb470a46c08549b0de317432d7701e4526759525 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
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";
		});
	};
}