-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.js
65 lines (46 loc) · 1.34 KB
/
util.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const fs = require('fs-extra')
const path = require('path')
const yaml = require('js-yaml')
module.exports = {
generateData: (distPath, files) => {
let metainfo = []
// collect category data of each file in content directory
files.forEach((file) => {
// only .yaml files found in apps directory
if (file.startsWith('apps/') && file.endsWith('.yaml')) {
const fileInfo = path.parse(file)
const data = yaml.safeLoad(fs.readFileSync(`content/${file}`))
/*const dataCategory = data.category
if (dataCategory) {
if (!categories[dataCategory]) {
categories[dataCategory] = []
}
const fileInfo = path.parse(file)
categories[dataCategory].push({
name: data.name,
image_src: data.image_src,
link: fileInfo.dir
})
}*/
let newData = {}
if (data.name)
newData.name = data.name
if (data.image_src)
newData.image_src = data.image_src
if (data.category)
newData.category = data.category
if (data.time)
newData.time = data.time
/*
newData.name = data.name || ''
newData.image_src = data.image_src || ''
newData.category = data.category || ''
newData.time = data.time || ''
*/
newData.link = fileInfo.dir
metainfo.push(newData)
}
})
fs.writeFileSync(`${distPath}/static/data.yaml`, yaml.safeDump({ 'metainfo': metainfo }))
}
}