-
Notifications
You must be signed in to change notification settings - Fork 23
/
build.js
199 lines (173 loc) · 6.6 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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
var metalsmith = require('metalsmith'),
branch = require('metalsmith-branch'),
collections = require('metalsmith-collections'),
excerpts = require('metalsmith-better-excerpts'),
layouts = require('metalsmith-layouts'),
pagination = require('metalsmith-pagination'),
asciidoc = require('metalsmith-asciidoc'),
markdown = require('metalsmith-markdown'),
jade = require('metalsmith-jade'),
less = require('metalsmith-less'),
permalinks = require('metalsmith-permalinks'),
serve = require('metalsmith-serve'),
watch = require('metalsmith-watcher'),
redirect = require('metalsmith-redirect'),
msIf = require('metalsmith-if'),
feed = require('metalsmith-feed'),
drafts = require('metalsmith-drafts'),
gist = require('metalsmith-gist'),
moment = require('moment'),
fs = require('fs');
var versions = require('./versions.js')
moment.updateLocale('en', {
calendar : {
lastDay : '[Yesterday, ] MMM Do',
sameDay : '[Today, ] MMM Do',
lastWeek : '[last] dddd[, ] MMM Do',
sameElse : 'll'
}
});
build();
function build() {
var serveAndWatch = process.argv.length > 2 && process.argv[2] === 'serve',
metadata = JSON.parse(fs.readFileSync('./site.json', 'utf8'));
metadata.devMode = serveAndWatch;
metadata.CURRENT_RELEASE = versions.CURRENT_RELEASE;
metalsmith(__dirname)
.metadata(metadata)
.source('./src')
.destination('./build')
// Write pages in asciidoc or markdown
.use(asciidoc())
.use(markdown())
.use(jade())
// use less for css
.use(less())
// Hide draft posts
.use(drafts())
// Make it easy to insert gists into your posts
.use(gist())
// For the blog index page
.use(excerpts({
pruneLength: 500,
stripTags: false,
}))
.use(collections({
posts: {
pattern: 'posts/**.html',
sortBy: 'publishDate',
reverse: true
}
}))
.use(
pagination({
'collections.posts': {
perPage: 3,
layout: 'archive.jade',
first: 'archive.html',
path: 'archive/:num/index.html',
filter: function (page) {
return !page.private
},
pageMetadata: {
title: 'Archive'
}
}
})
)
// URL rewriting for permalinks
.use(branch('posts/**.html')
.use(permalinks({
pattern: 'posts/:title',
relative: false
})))
.use(branch('!posts/**.html')
.use(branch('!index.md').use(permalinks({
relative: false
}))))
// Jade templates
.use(layouts({
engine: 'jade',
moment: moment
}))
// RSS Feed
.use(feed(
{
collection: 'posts',
pubDate: new Date(),
postDescription: function(file) {
// Ugly hack to set publish date on RSS feed.
// See https://issues.jboss.org/browse/SWARM-441 and https://github.com/hurrymaplelad/metalsmith-feed/issues/13
file.date = file.publishDate;
return file.less || file.excerpt || file.contents;
}
}
))
// when we run as `node build serve` we'll serve the site and watch
// the files for changes. Note: This does not reload when templates
// change, only when the content changes
.use(msIf(
serveAndWatch,
serve({
port: 8080,
verbose: true
})))
.use(msIf(
serveAndWatch,
watch()
))
.use(redirect({
'/download/swarmtool': 'http://repo2.maven.org/maven2/io/thorntail/swarmtool/'+ versions.CURRENT_RELEASE + '/swarmtool-' + versions.CURRENT_RELEASE + '-standalone.jar',
'/download/microprofile-hollow-thorntail': 'http://repo2.maven.org/maven2/io/thorntail/servers/microprofile/' + versions.CURRENT_RELEASE + '/microprofile-' + versions.CURRENT_RELEASE + '-hollow-thorntail.jar',
'/download/microprofile-jpa-hollow-thorntail': 'http://repo2.maven.org/maven2/io/thorntail/servers/microprofile-jpa/' + versions.CURRENT_RELEASE + '/microprofile-jpa-' + versions.CURRENT_RELEASE + '-hollow-thorntail.jar',
'/download/web-hollow-thorntail': 'http://repo2.maven.org/maven2/io/thorntail/servers/web/' + versions.CURRENT_RELEASE + '/web-' + versions.CURRENT_RELEASE + '-hollow-thorntail.jar',
'/download/keycloak-thorntail': 'http://repo2.maven.org/maven2/io/thorntail/servers/keycloak/' + versions.CURRENT_RELEASE + '/keycloak-' + versions.CURRENT_RELEASE + '-thorntail.jar',
'/download/management-console-thorntail': 'http://repo2.maven.org/maven2/io/thorntail/servers/management-console/' + versions.CURRENT_RELEASE + '/management-console-' + versions.CURRENT_RELEASE + '-thorntail.jar',
'/download/swagger-ui-thorntail': 'http://repo2.maven.org/maven2/io/thorntail/servers/swagger-ui/' + versions.CURRENT_RELEASE + '/swagger-ui-' + versions.CURRENT_RELEASE + '-thorntail.jar',
'/userguide/2017-10-0': 'https://wildfly-swarm.gitbooks.io/wildfly-swarm-users-guide/v/2017.10.0/',
'/refguide/2017-10-0': 'https://reference.wildfly-swarm.io/v/2017.10.0/',
'/howto/2017-10-0': 'https://wildfly-swarm.gitbooks.io/wildfly-swarm-howto/v/2017.10.0/',
'/docs/2017-11-0': 'http://docs.wildfly-swarm.io/2017.11.0/',
'/docs/2017-12-1': 'http://docs.wildfly-swarm.io/2017.12.1/',
'/docs/2018-1-0': 'http://docs.wildfly-swarm.io/2018.1.0/',
'/docs/2018-2-0': 'http://docs.wildfly-swarm.io/2018.2.0',
'/docs/2018-3-3': 'http://docs.wildfly-swarm.io/2018.3.3',
'/docs/2018-4-1': 'http://docs.wildfly-swarm.io/2018.4.1',
'/docs/2018-5-0': 'http://docs.wildfly-swarm.io/2018.5.0',
'/docs/2-0-0-Final': 'http://docs.wildfly-swarm.io/2.0.0.Final',
'/docs/2-1-0-Final': 'http://docs.wildfly-swarm.io/2.1.0.Final',
'/docs/2-2-0-Final': 'http://docs.wildfly-swarm.io/2.2.0.Final',
'/docs/HEAD': 'http://docs.wildfly-swarm.io/2.3.0.Final-SNAPSHOT',
}))
.build(function (err) {
if (err) {
console.log(err);
throw err;
}
else {
console.log('Site build complete.');
if (process.argv.length > 2 && process.argv[2] === 'publish') {
publish();
}
}
});
}
function publish() {
var ghpages = require('gh-pages'),
path = require('path'),
options = {
user: {
name: 'Project:Odd CI',
email: '[email protected]'
},
dotfiles: true
};
ghpages.publish(path.join(__dirname, 'build'), options, function(err) {
if (err) {
console.error("Cannot publish site. " + err);
throw err;
}
else
console.log('Site published.');
});
}