-
Notifications
You must be signed in to change notification settings - Fork 0
/
issues.js
71 lines (52 loc) · 1.68 KB
/
issues.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
66
67
68
69
70
71
const axios = require('axios');
const fs = require('fs');
const path = require('path');
const argv = process.argv;
const blogUrl = argv[2];
const assert = require('assert');
assert(blogUrl, '请输入github blog地址');
async function run() {
const response = await axios(blogUrl + '/issues');
const articles = response.data;
let updateTime = {};
articles.forEach(async (blog) => {
let { labels } = blog;
let post = '';
let metas = ['---'];
let tags = [];
let cats = [];
let blogName = null;
labels = labels.filter((label) => {
if (/^blog-(.*)/.test(label.name)) {
blogName = label.name.slice(5);
return false;
} else if (/^cat-/.test(label.name)) {
cats.push('- ' + label.name.slice(4));
return true;
} else {
tags.push('- ' + label.name);
return true;
}
});
if (!blogName) {
console.info('Not a blog issue, skip, issue id:', blog.number);
return;
}
metas.push(`title: ${blog.title}`)
// console.log(blog);
metas.push('date: ' + blog.created_at);
updateTime[blog.number] = blog.updated_at;
if (cats.length) {
metas.push('categories:');
metas = metas.concat(cats);
}
if (tags.length) {
metas.push('tags:');
metas = metas.concat(tags);
}
metas.push('---');
post = metas.join('\n') + '\n\n' + blog.body;
fs.writeFileSync(path.join(__dirname, `./source/_posts/${blogName}.md`), post);
});
}
run();