14 lines
345 B
JavaScript
14 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'
|
||
|
}
|
||
|
}
|
||
|
}
|