aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/rehypeLazyImages.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/rehypeLazyImages.ts')
-rw-r--r--src/plugins/rehypeLazyImages.ts13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/plugins/rehypeLazyImages.ts b/src/plugins/rehypeLazyImages.ts
new file mode 100644
index 0000000..eb470a4
--- /dev/null
+++ b/src/plugins/rehypeLazyImages.ts
@@ -0,0 +1,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";
+ });
+ };
+}