forked from Automattic/mongoose
-
Notifications
You must be signed in to change notification settings - Fork 1
/
website.js
72 lines (62 loc) · 1.89 KB
/
website.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
var fs= require('fs')
var jade = require('jade')
var package = require('./package')
var hl = require('./docs/helpers/highlight')
var linktype = require('./docs/helpers/linktype')
var href = require('./docs/helpers/href')
var klass = require('./docs/helpers/klass')
// add custom jade filters
require('./docs/helpers/filters')(jade);
// use last release
package.version = getVersion();
package.unstable = getUnstable(package.version);
var filemap = require('./docs/source');
var files = Object.keys(filemap);
files.forEach(function (file) {
var filename = __dirname + '/' + file;
jadeify(filename, filemap[file]);
if ('--watch' == process.argv[2]) {
fs.watchFile(filename, { interval: 1000 }, function (cur, prev) {
if (cur.mtime > prev.mtime) {
jadeify(filename, filemap[file]);
}
});
}
});
function jadeify (filename, options) {
options || (options = {});
options.package = package;
options.hl = hl;
options.linktype = linktype;
options.href = href;
options.klass = klass;
jade.renderFile(filename, options, function (err, str) {
if (err) return console.error(err.stack);
var newfile = filename.replace('.jade', '.html')
fs.writeFile(newfile, str, function (err) {
if (err) return console.error('could not write', err.stack);
console.log('%s : rendered ', new Date, newfile);
});
});
}
function getVersion () {
var hist = fs.readFileSync('./History.md','utf8').replace(/\r/g, '\n').split('\n');
for (var i = 0; i < hist.length; ++i) {
var line = (hist[i] || '').trim();
if (!line) continue;
var match = /^\s*([^\s]+)\s/.exec(line);
if (match && match[1])
return match[1];
}
throw new Error('no match found');
}
function getUnstable(ver) {
ver = ver.replace("-pre");
var spl = ver.split('.');
spl = spl.map(function (i) {
return parseInt(i);
});
spl[1]++;
spl[2] = "x";
return spl.join('.');
}