-
Notifications
You must be signed in to change notification settings - Fork 46
/
build.js
75 lines (64 loc) · 2.16 KB
/
build.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
74
75
const fs = require('fs')
const path = require('path')
const excludes = ['.git', '.idea', 'node_modules', '.netlify']
const directories = []
const { years, title, banner } = require('./config')
fs.readdirSync(path.join(__dirname)).forEach(file => {
if (fs.lstatSync(path.join(__dirname, file)).isDirectory()) {
if (!excludes.includes(file)) {
directories.push(file)
}
}
})
let gameTemplateMap = {}
let isBttonExist = false
for (const { year, header, description } of years) {
gameTemplateMap[year] = `
<div class="main-container">
<div class="topic">
<h1 class="heading">${header}</h1>
<p class="desc">${description}</p>
${
isBttonExist
? ''
: `<a
class="hacking"
href="https://github.com/WebForFunThailand/noobtoberfest"
target="_blank"
>START HACKING</a>`
}
</div>
</div>
`
isBttonExist = true
}
directories.forEach(directory => {
let info = fs.readFileSync(path.join(__dirname, directory, 'info.json'))
info = JSON.parse(info.toString())
const template = `
<div class="main-container">
<div class="game">
<a class="head" href="/${directory}" target="_blank">
<h3 class="play-keyword">Play - </h3>
<h3>${info.name}</h3>
</a>
<p style="color: #57606f">${info.description}</p>
👉 <a href="${info.facebook}" target="_blank" class="author">${info.author}</a>
</div>
</div>
`
gameTemplateMap[info.year] += template
})
const totalTemplate = years.map(({ year }) => gameTemplateMap[year]).join('')
let htmlTemplate = fs
.readFileSync(path.join(__dirname, 'template.html'))
.toString()
htmlTemplate = htmlTemplate.replace('#include-banner-title', banner.title)
htmlTemplate = htmlTemplate.replace(
'#include-banner-description',
banner.description
)
htmlTemplate = htmlTemplate.replace('#include-template', totalTemplate)
htmlTemplate = htmlTemplate.replace('#include-title', title)
fs.writeFileSync('index.html', htmlTemplate)
console.log('Done~')