forked from wildfly-swarm/wildfly-swarm.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
196 lines (172 loc) · 6.76 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
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/org/wildfly/swarm/swarmtool/'+ versions.CURRENT_RELEASE + '/swarmtool-' + versions.CURRENT_RELEASE + '-standalone.jar',
'/download/microprofile-hollowswarm': 'http://repo2.maven.org/maven2/org/wildfly/swarm/servers/microprofile/' + versions.CURRENT_RELEASE + '/microprofile-' + versions.CURRENT_RELEASE + '-hollowswarm.jar',
'/download/keycloak-swarm': 'http://repo2.maven.org/maven2/org/wildfly/swarm/servers/keycloak/' + versions.CURRENT_RELEASE + '/keycloak-' + versions.CURRENT_RELEASE + '-swarm.jar',
'/download/management-console-swarm': 'http://repo2.maven.org/maven2/org/wildfly/swarm/servers/management-console/' + versions.CURRENT_RELEASE + '/management-console-' + versions.CURRENT_RELEASE + '-swarm.jar',
'/download/swagger-ui-swarm': 'http://repo2.maven.org/maven2/org/wildfly/swarm/servers/swagger-ui/' + versions.CURRENT_RELEASE + '/swagger-ui-' + versions.CURRENT_RELEASE + '-swarm.jar',
'/userguide/HEAD': 'https://wildfly-swarm.gitbooks.io/wildfly-swarm-users-guide/content/',
'/refguide/HEAD': 'https://reference.wildfly-swarm.io/',
'/howto/HEAD': 'https://howto.wildfly-swarm.io/',
'/userguide/1-0-0-CR2': 'https://wildfly-swarm.gitbooks.io/wildfly-swarm-users-guide/content/v/56dc244fbc0061d12d923c3b3f964b6c8d2d7e78/',
'/userguide/1-0-0-Final': 'https://wildfly-swarm.gitbooks.io/wildfly-swarm-users-guide/content/v/6a00bb344527303f784f541ee2fb93abec4a1ef4/',
'/userguide/2016-8-1': 'https://wildfly-swarm.gitbooks.io/wildfly-swarm-users-guide/content/v/8cca257df347646706d7967e93f0588bc75681a9/',
'/userguide/2016-9': 'https://wildfly-swarm.gitbooks.io/wildfly-swarm-users-guide/content/v/2016.9/',
'/userguide/2016-10-0': 'https://wildfly-swarm.gitbooks.io/wildfly-swarm-users-guide/content/v/34f88c070cc80d697274327282004526316f7851/',
'/userguide/2016-11-0': 'https://wildfly-swarm.gitbooks.io/wildfly-swarm-users-guide/content/v/2016.11.0/',
'/userguide/2016-12-0': 'https://wildfly-swarm.gitbooks.io/wildfly-swarm-users-guide/content/v/2016.12.0/',
'/userguide/2016-12-1': 'https://wildfly-swarm.gitbooks.io/wildfly-swarm-users-guide/content/v/2016.12.1/',
'/userguide/2017-1-1': 'https://wildfly-swarm.gitbooks.io/wildfly-swarm-users-guide/content/v/2017.1.1/',
'/userguide/2017-2-0': 'https://wildfly-swarm.gitbooks.io/wildfly-swarm-users-guide/content/v/2017.2.0/',
'/refguide/2017-2-0': 'https://reference.wildfly-swarm.io/v/2017.2.0/',
'/howto/2017-2-0': 'https://howto.wildfly-swarm.io/v/2017.2.0/',
}))
.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.');
});
}