forked from GDGToulouse/devfest-theme-hugo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathicons.js
29 lines (24 loc) · 931 Bytes
/
icons.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
const {readFileSync, writeFileSync} = require('fs');
const {sync: glob} = require('glob');
const {Logger, LogLevel, colorEmojiConfig} = require('plop-logger');
Logger.config = colorEmojiConfig;
const logger = Logger.getLogger('icons');
logger.level = LogLevel.All;
let svgFiles = `src/icons/*.svg`;
logger.info('SVG aggregation of', svgFiles);
const data = glob(svgFiles)
.map(file => {
const parts = file.split('/');
const id = parts[parts.length - 1].split('.')[0];
logger.debug('handle', id);
return readFileSync(file, 'utf8')
.replace(`<svg xmlns="http://www.w3.org/2000/svg"`, `\t<symbol id="${id}"`)
.replace(`</svg>`, `\t</symbol>`);
}
);
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="0" height="0" class="visually-hidden">
${data.join('\n')}
</svg>`;
const file = 'static/icons.svg';
logger.info('Generate', file);
writeFileSync(file, svg, {flag: 'w'});