-
Notifications
You must be signed in to change notification settings - Fork 2
/
gen.js
74 lines (68 loc) · 1.91 KB
/
gen.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
72
73
const fs = require('fs');
const {execSync} = require('child_process');
const Lokka = require('lokka').Lokka;
const Transport = require('lokka-transport-http').Transport;
const Hexo = require('hexo');
const token = process.env.GITHUB_TOKEN;
const client = new Lokka({
transport: new Transport('https://api.github.com/graphql', {
headers: {
Authorization: `bearer ${token}`
}
})
});
client.query(`
{
repository(owner: "gwuhaolin", name: "blog") {
issues(first: 100, orderBy: {field: CREATED_AT, direction: ASC}, states: [OPEN], filterBy: {createdBy: "gwuhaolin"}) {
edges {
node {
title
body
createdAt
url
labels(first: 100) {
edges {
node {
name
}
}
}
}
}
totalCount
}
}
}
`).then(result => {
result.repository.issues.edges.forEach((em) => {
const {title, body, createdAt, url, labels} = em.node;
const tags = labels.edges.map(em => em.node.name);
const mdContent = `---
title: ${title}
date: ${createdAt}
url: ${url}
tags:
${tags.map(tag => ` - ${tag}`).join('\n')}
---
${body}`;
fs.writeFileSync(`./source/_posts/${title}.md`, mdContent);
});
console.info('更新 md 完毕');
execSync(`rm -rf ./public`);
fs.mkdirSync('./public');
fs.writeFileSync('./public/CNAME', 'wuhaolin.cn\nwww.wuhaolin.cn');
fs.writeFileSync('./public/google0cfdf15fc45ac515.html', 'google-site-verification: google0cfdf15fc45ac515.html');
const hexo = new Hexo();
hexo.init().then(function () {
hexo.call('generate',{}).then(function () {
execSync(`rm -rf docs`);
execSync(`mv public docs`);
console.log('网站生成完毕');
process.exit(0);
});
});
}).catch(err => {
console.error(err);
process.exit(1);
});