diff options
Diffstat (limited to 'src/plugins')
| -rw-r--r-- | src/plugins/rehypeLazyImages.ts | 13 |
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"; + }); + }; +} |
