dc09.ru/rehype-image-attr.mjs

13 lines
345 B
JavaScript

// Adds some HTML attributes to images,
// only loading=lazy for now
import { selectAll } from 'unist-util-select'
export default function rehypeImageAttr() {
return (tree, file) => {
const imgs = selectAll('element[tagName=img]', tree)
for (let img of imgs) {
img.properties.loading = 'lazy'
}
}
}