-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
35 lines (31 loc) · 960 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const glob = require('glob');
const path = require('path');
const defaults = {
heading: true,
headingLevel: 6,
include: './**/*.{gif,jpg,png,svg}',
};
module.exports = function LOCALIMAGE(content, _options, config) {
const settings = Object.assign({}, defaults, _options);
const basePath = path.resolve(path.dirname(config.originalPath));
const pattern = path.join(basePath, settings.include);
return glob
.sync(pattern, {
ignore: '**/node_modules/**',
})
.map(filePath => {
const imageName = path.basename(filePath, path.extname(filePath));
const imageSrc = path.relative(basePath, filePath);
return [
JSON.parse(settings.heading)
? `${Array(Number(settings.headingLevel))
.fill('#')
.join('')} ${imageName}`
: null,
`![Alt text](${imageSrc} "${imageName}")`,
]
.filter(Boolean)
.join('\n');
})
.join('\n');
};