rehype-image-attr; descriptions for plugins

This commit is contained in:
DarkCat09 2023-07-24 17:52:51 +04:00
parent d51f0d3f03
commit 9dda240ebe
4 changed files with 152 additions and 21 deletions

13
rehype-image-attr.mjs Normal file
View file

@ -0,0 +1,13 @@
// 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'
}
}
}