forked from TritonDataCenter/node-in-the-industry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
33 lines (30 loc) · 1.09 KB
/
main.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
var trumpet = require("trumpet")
var fs = require("fs")
var path = require("path")
var index = fs.createReadStream("index.html")
var companies = fs.readdirSync(__dirname + "/data")
// pick 4 at random
var select = []
while (select.length < 4 && companies.length) {
var i = Math.floor(Math.random() * companies.length)
if (i === companies.length) continue
select.push(companies[i])
companies.splice(i, 1)
}
var html = select.map(function (company) {
var compdir = path.resolve(__dirname, "data", company)
var quote = path.resolve(compdir, "quote.html")
var logo = path.relative(process.cwd(), compdir) + "/logo.png"
return '<li class="' + company + '">' +
'<img src="' + logo + '" alt="logo" height=34>' +
fs.readFileSync(quote) +
'</li>'
}).join("\n")
index.pipe(trumpet())
.select("div#quotes", function (div) {
div.update(function () { return '<h2>Node.js in the Industry</h2><ul>' + html + '</ul><h2 style="clear:both"><a href="/industry/">More...</a></h2>' })
})
.pipe(fs.createWriteStream(".index.html"))
.on("close", function () {
fs.rename(".index.html", "index.html")
})