-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.js
More file actions
48 lines (40 loc) · 1.33 KB
/
build.js
File metadata and controls
48 lines (40 loc) · 1.33 KB
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
const ejs = require('ejs')
const fs = require('fs')
const { createFolder, travel } = require('./common/util.js')
const config = require('./config.js')
const {templates} = config
// 渲染首页,404,contribute
ejs.renderFile('./view/index.ejs', config, {}, function(err, str){
createFolder('./dist/index.html')
fs.writeFileSync('./dist/index.html',str)
});
ejs.renderFile('./view/404.ejs', config, {}, function(err, str){
createFolder('./dist/404.html')
fs.writeFileSync('./dist/404.html',str)
});
ejs.renderFile('./view/contribute.ejs', config, {}, function(err, str){
createFolder('./dist/contribute.html')
fs.writeFileSync('./dist/contribute.html',str)
});
// 渲染gif制作页
templates.forEach((template, index)=>{
const htmlPath = `./dist/gif/${template.name}.html`
createFolder(htmlPath)
const data = Object.assign({}, config, {template}, {index} )
ejs.renderFile('./view/gif.ejs', data, {}, function(err, str){
fs.writeFileSync(htmlPath, str)
});
})
// 复制其他资源和模板
travel('./view', pathname => {
if(pathname.indexOf('.ejs') < 0){
const distPath = `./dist/${pathname.split('view')[1]}`
createFolder(distPath)
fs.copyFileSync(pathname, distPath,)
}
})
travel('./template', pathname => {
const distPath = `./dist/${pathname}`
createFolder(distPath)
fs.copyFileSync(pathname, distPath,)
})