dc09.ru/rehype-image-attr.mjs

14 lines
345 B
JavaScript
Raw Permalink Normal View History

// 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'
}
}
}