-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathpublish.js
More file actions
49 lines (39 loc) · 1.26 KB
/
publish.js
File metadata and controls
49 lines (39 loc) · 1.26 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
48
49
/**
* Created by bjdmeest on 10/06/2016.
* Modified by Dylan Van Assche on 12/02/2021.
*/
var fs = require('fs');
var path = require('path');
var dateString = (new Date()).toISOString().split('T')[0].replace(/-/g, '');
try {
if (!fs.existsSync (path.resolve(__dirname, 'docs'))) {
fs.mkdirSync (path.resolve(__dirname, 'docs'));
}
fs.mkdirSync (path.resolve(__dirname, 'docs', dateString));
} catch (e) {
}
var files = fs.readdirSync (path.resolve(__dirname, 'docs'));
var dirs = [];
for (var i = 0; i < files.length; i++) {
if (fs.lstatSync (path.resolve(__dirname, 'docs', files[i])).isDirectory()) {
dirs.push(files[i]);
}
}
dirs.sort();
dirs.reverse();
if (dirs[0] === "resources") {
dirs.splice (0, 1);
}
if (dirs[0] === dateString) {
dirs.splice (0, 1);
}
// First version, set previous version to this one
if (dirs.length == 0) {
dirs.push (dateString)
}
var html = fs.readFileSync ('./rendered.html', 'utf8');
html = html.replace (/%thisDate%/g, dateString);
html = html.replace (/%prevDate%/g, dirs[0]);
fs.writeFileSync (path.resolve (__dirname, 'docs', 'index.html'), html);
html = html.replace (/\.\/resources/g, '../resources');
fs.writeFileSync (path.resolve(__dirname, 'docs', dateString, 'index.html'), html);