forked from zyronon/douyin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess-post-list.js
47 lines (40 loc) · 982 Bytes
/
process-post-list.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
import fs from 'fs'
import { users } from './user/data.js'
let read = './post/data/'
let max = 0
let map = []
//判断是不是目录
const dirs = fs.readdirSync(read)
dirs.forEach((dictName) => {
formatDict(read, dictName)
})
function formatDict(dir, name) {
let filePath = dir + name
let saveFileStr = fs.readFileSync(filePath, 'utf8')
let inputData = JSON.parse(saveFileStr)
map.push({
userId: name,
list: inputData,
})
if (max < inputData.length) max = inputData.length
}
let newList = []
// max = 5
for (let i = 0; i < max; i++) {
map.map((v) => {
if (v.list.length > i) {
let data = v.list[i]
newList.push(data)
}
})
}
// console.log(newList)
let data = newList.slice(0, 6)
data.map((v) => {
let u = users.find((a) => a.uid == v.author_user_id)
if (u) {
v.author = u
}
})
fs.writeFileSync('./posts6.json', JSON.stringify(data, null, 2))
fs.writeFileSync('./posts.json', JSON.stringify(newList.slice(6), null, 2))