-
Notifications
You must be signed in to change notification settings - Fork 0
/
caps.js
43 lines (37 loc) · 1.15 KB
/
caps.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
36
37
38
39
40
41
42
43
var glob = require('glob')
module.exports = {
getCaps: () => {
const images = glob.sync('images/**/**/*.*')
const caps = {}
images.forEach(image => {
const [ basePath, country, brewery, name ] = image.split('/')
if (!Object.keys(caps).includes(country)) {
caps[country] = {
name: country,
total: 0,
breweries: {},
}
}
if (!Object.keys(caps[country].breweries).includes(brewery)) {
caps[country].breweries[brewery] = {
name: brewery,
beers: [],
}
}
const cleanName = name && name.split('.').shift().replace(/\(.*\)$/, '').trim()
const tags = name && name.match(/\(.*\)/)
const cleanTags = tags && tags[0].replace('(', '').replace(')', '')
caps[country].total++
caps[country].breweries[brewery].beers.push({
image,
name: cleanName,
tags: cleanTags,
})
})
return {
caps,
total: images.length,
countries: Object.keys(caps).length - 2, // Remove unknown + non beer categories
}
}
}