-
Notifications
You must be signed in to change notification settings - Fork 2
/
statix.js
145 lines (107 loc) · 3.79 KB
/
statix.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
var fs = require("fs");
var path = require("path");
module.exports = {
source_dir : "project", // `source_dir` is the directory where all your source files are.
output_dir: "deploy", // `output_dir` is the directory you want to compile your static site to.
template_engine : "swig", // the npm package name of the template engine, only engines supported by consolidate.js will work
template_dir : "project/templates", // Only relevant if using swig : The directory where all your templates are.
/*
Literal regexes here. Statix won't include anything, unless it matches an `include_pattern` and also does
not match an `exclude_pattern`. Checks against the full path, i.e. /Users/your.name/some/dir/site/blah.html
*/
include_patterns : [
/^(.*)$/
],
exclude_patterns : [
/^(.*)(base\.html{1})$/,
/^(.*)(\/templates{1})(.*)$/
],
/*
An array of the pages to be rendered with the template engine.
`output` is where your page will eventually live, in the static version of the site. I.e. "{output_dir}/{page.output}"
`source` is where your template lives. I.e. "{source_dir}{page.source}"
`data` is an object of variables you want to pass through to the template when it gets rendered.
*/
pages : [
{
output : "index.html",
source : "templates/pages/home.html",
data : {}
},
{
output : "404.html",
source : "templates/404.html",
data : {}
},
{
output : "500.html",
source : "templates/500.html",
data : {}
}
],
/*
`global_data` is an object that gets passed to all pages. Note, if you set `global_data.someProp` to something
and also have `page.data.someProp`, the latter will take precedence.
*/
global_data: {
settings : {
TEMPLATE_DEBUG : true
},
STATIC_URL : "static/"
},
/*
Like `global_data`, but `build_data` only gets passed to the renderer when you build, not when viewing locally through the webserver.
`build_data` properties take precedence over `global_data` properties.
*/
build_data : {
settings : {
TEMPLATE_DEBUG: false
}
},
/*
If you need to process some things before you're ready to generate the pages (either through the web server or compilation),
you can use this `ready` method. Common use case, you need to grab a bunch of data from a database, and are using asynch i/o
Statix, does nothing until the `callback` passed to this method is called, so once you are done with everything you need to do,
simply call `callback();`
*/
ready : function (callback) {
callback();
},
/*
Statix gives you a hook to do whatever you want before the build actually happens. You can use this method to minify js/css,
compile scss stylesheets, etc. Just be sure to invoke the `done()` function when you are ready for Statix to do it's thing.
*/
preBuild : function (done) {
done();
},
/*
Just like `preBuild()` but this method gets called after Statix has generated the static site. You can use this to
cleanup some files, git commit/push, or whatever you feel like. Just be sure to invoke the `done()` function afterwards.
*/
postBuild : function (done) {
function moveFiles(from, to) {
from = (from[0] == "/") ? from : process.cwd() + "/" + from;
to = (to[0] == "/") ? to : process.cwd() + "/" + to;
var fromStats = fs.statSync(from);
var fromName = from.substr(from.lastIndexOf("/"));
if(fromStats.isDirectory()){
if(!path.existsSync(to)){
console.log(to);
fs.mkdirSync(to);
}
var files = fs.readdirSync(from);
for(var i = 0; i < files.length; i ++){
moveFiles(from + "/" + files[i], to + "/" + files[i]);
}
fs.rmdirSync(from);
}
else{
fs.writeFileSync(to, fs.readFileSync(from, 'utf-8'));
fs.unlinkSync(from);
}
}
moveFiles.bind(this);
moveFiles(this.output_dir + "/static-local", this.output_dir);
done();
}
}