forked from swapagarwal/swag-for-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-data.js
More file actions
35 lines (31 loc) · 1.04 KB
/
Copy pathget-data.js
File metadata and controls
35 lines (31 loc) · 1.04 KB
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 swagImages = [];
const fileNames = [];
const swagList = require('./data.json').map(swag => {
// @todo: remove once `active: Boolean` is added to data.json
if (swag.tags.includes('hacktoberfest')) {
return false;
}
// Generate unique filename
// @todo: do we want to force jpeg as the image format?
// const extension = swag.image.split('.').pop();
const extension = 'jpg';
const fileBase = swag.name
.replace(/[^a-z0-9]/gi, '_')
.replace(/_{2,}/g, '_')
.toLowerCase();
let index = 0;
let fileName = `${fileBase}.${extension}`;
while (fileNames.includes(fileName)) {
fileName = `${fileBase}-${++index}.${extension}`;
}
// End generate unique filename
swagImages.push({
url: swag.image,
file: fileName
});
swag.image = `/assets/swag-img/${fileName}`;
fileNames.push(fileName);
return swag;
// @todo: remove (if needed) once `active: Boolean` is added to data.json
}).filter(Boolean);
module.exports = { swagList, swagImages };