blob: afc61c468dc534a1cb0f74644d653fb4996f8ff1 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
import type { Image } from 'mdast';
import { visit } from 'unist-util-visit';
import type { VFile } from 'vfile';
export default function toRemarkCollectImages() {
return () =>
async function (tree: any, vfile: VFile) {
if (typeof vfile?.path !== 'string') return;
const imagePaths = new Set<string>();
visit(tree, 'image', function raiseError(node: Image) {
imagePaths.add(node.url);
});
vfile.data.imagePaths = Array.from(imagePaths);
};
}
|