-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.js
260 lines (249 loc) · 7.47 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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
const browserSync = require('browser-sync')
const Metalsmith = require('metalsmith')
const autoprefixer = require('metalsmith-autoprefixer')
const discoverHelpers = require('metalsmith-discover-helpers')
const discoverPartials = require('metalsmith-discover-partials')
const inplace = require('@metalsmith/in-place')
const fingerprint = require('metalsmith-fingerprint-ignore')
const layouts = require('@metalsmith/layouts')
const sass = require('@metalsmith/sass')
const sitemap = require('metalsmith-sitemap')
const redirect = require('metalsmith-redirect')
const robots = require('metalsmith-robots')
const watch = require('metalsmith-watch')
const i18next = require('metalsmith-i18next')
const collections = require('@metalsmith/collections')
const rss = require('@metalsmith/rss')
const jsBundle = require('@metalsmith/js-bundle')
const packageJson = require('./package.json')
const defaultLang = 'en'
const env = process.env.NODE_ENV || 'DEV'
const lang = (process.env.SITE_LANG || defaultLang).toLocaleLowerCase()
const dest = lang === 'en' ? 'public' : 'public-' + lang
const languages = {
en: 'English',
fr: 'français',
de: 'Deutsch'
}
const filterDefaults = ({
en: {},
fr: { language: languages.fr },
de: { language: languages.de }
})[lang]
const allProfiles = require(`./locales/${lang}/featured-profiles.json`)
const priorityProfiles = allProfiles.filter(p => p.priority > 0).sort((a, b) => a.priority - b.priority)
const featuredProfiles = [...allProfiles].sort((a, b) => a.domain.localeCompare(b.domain))
const bootstrapVersion = packageJson.dependencies.bootstrap
console.log('Building for environment:', env, lang)
const ENV_OPTIONS = {
DEV: {
'site-url': {
en: 'http://localhost:8080',
fr: 'https://fr.test.go.eco',
de: 'https://de.test.go.eco'
},
watch: true,
profiles: 'https://test.profiles.eco',
trustmark: 'https://test-trust.profiles.eco',
intercomAppID: 'gt94nkkh',
searchUrl: 'https://test-search.go.eco',
sentryUri: 'https://js.sentry-cdn.com/75afeef7f5f34bd1b6e3e86120528892.min.js',
noindex: true,
makeOfferForm: 'https://docs.google.com/forms/d/e/1FAIpQLScdAh6F_o-CXehz2bSfJKLToxUUM9U4vK0NE5GdDS6NCiSvAQ/formResponse'
},
TST: {
'site-url': {
en: 'https://test.go.eco',
fr: 'https://fr.test.go.eco',
de: 'https://de.test.go.eco'
},
watch: false,
profiles: 'https://test.profiles.eco',
trustmark: 'https://test-trust.profiles.eco',
intercomAppID: 'gt94nkkh',
searchUrl: 'https://test-search.go.eco',
sentryUri: 'https://js.sentry-cdn.com/75afeef7f5f34bd1b6e3e86120528892.min.js',
noindex: true,
makeOfferForm: 'https://docs.google.com/forms/d/e/1FAIpQLScdAh6F_o-CXehz2bSfJKLToxUUM9U4vK0NE5GdDS6NCiSvAQ/formResponse'
},
PRD: {
'site-url': {
en: 'https://go.eco',
de: 'https://kauf.eco',
fr: 'https://allez.eco'
},
watch: false,
profiles: 'https://profiles.eco',
trustmark: 'https://trust.profiles.eco',
intercomAppID: 'hsovcclh',
searchUrl: 'https://search.go.eco',
sentryUri: 'https://js.sentry-cdn.com/b58e840db28c47409688bc4dded2c97a.min.js',
makeOfferForm: 'https://docs.google.com/forms/d/e/1FAIpQLScjnQNdyxwhKLM0s7l8h3AKp66WcTY72Qrw5JMC3s9m_k7uVA/formResponse'
}
}
const options = ENV_OPTIONS[env]
console.log('Using options:', options)
const siteUrl = options['site-url'][lang] || options['site-url'].en
const sitemapLinks = () => {
return (files, metalsmith, done) => {
for (const [path, file] of Object.entries(files)) {
if (path.endsWith('.html')) {
if (lang !== defaultLang && !file.i18nNamespace) {
file.exclude = true
file.redirectTo = '/'
} else if (file.i18nNamespace) {
file.sitemapLinks = Object.entries(options['site-url']).map(e => ({ lang: e[0], url: e[1] + '/' + path.replace('index.html', '') }))
}
}
}
done()
}
}
const jsEntries = {}
jsEntries[`js/bootstrap/${bootstrapVersion}/bootstrap.custom.min`] = 'source/js/bootstrap.custom.js'
const ms = Metalsmith(__dirname)
.metadata({
year: new Date().getFullYear(),
'img-root': '/img',
'site-url': siteUrl,
'twitter-id': '@doteco',
livereload: options.watch,
profiles: options.profiles,
trustmark: options.trustmark,
intercomAppID: options.intercomAppID,
searchUrl: options.searchUrl,
sentryUri: options.sentryUri,
noindex: options.noindex,
makeOfferForm: options.makeOfferForm,
lang,
languages,
sites: options['site-url'],
filterDefaults,
featuredProfiles,
priorityProfiles,
bootstrapVersion
})
.source('./source')
.destination(dest)
.clean(false)
.use(discoverHelpers({
directory: './helpers'
}))
.use(sass({
entries: {
'./scss/main.scss': 'css/main.css'
},
style: 'compressed',
sourceMap: true,
sourceMapContents: true
}))
.use(autoprefixer())
.use(jsBundle({
entries: jsEntries,
sourcemap: true,
minify: true
}))
.use(fingerprint({
pattern: '{css/main.css,js/domain-search.js}'
}))
.use(i18next({
locales: [lang],
namespaces: ['global'],
pattern: '**/*.hbs',
engine: 'handlebars',
helpers: null,
path: ':file',
frontMatterKeys: ['title', 'description', 'excerpt']
}))
.use(discoverPartials({
directory: 'layouts/partials'
}))
.use(collections({
news: {
sortBy: 'pubdate',
reverse: true,
refer: false
},
studies: {
sortBy: 'title',
refer: false
}
}))
.use(inplace({
pattern: [
'**/*.hbs', '**/*.md.hbs'
]
}))
.use(layouts({
pattern: '**/*.html',
default: 'default.hbs'
}))
.use(sitemapLinks())
.use(sitemap({
privateProperty: 'exclude',
hostname: siteUrl,
links: 'sitemapLinks',
omitIndex: true
}))
.use(robots({
sitemap: siteUrl + '/sitemap.xml'
}))
.use(redirect({
frontmatter: true,
noindex: false,
redirections: {
'/registrars/policies/': '/policies/',
'/registrars/funding/': '/registrars/',
'/registrars/partners/': '/registrars/',
'/registrar': '/registrars/',
'/frequently-asked-questions': '/faq/',
'/shop': '/',
'/affiliate': '/',
'/bthechange2017': '/',
'/names/premiums/': '/search/',
'/partners/institute-of-public-environmental-affairs/': 'https://org.eco/',
'/news/the-world-needs-more-tigers-13eb6e5eb394': '/news/',
'/news/first-ever-domain-grants-program-wraps-up-583234092c10': '/news/',
'/news/understanding-your-aim-1d02eebce1e8': '/news/',
'/rss/': '/rss.xml',
'/feed/': '/rss.xml',
'/news/feed': '/rss.xml',
'/the-eco-story/': '/about/story/'
}
}))
.use(rss({
feedOptions: {
title: '.eco news',
site_url: siteUrl
},
collection: 'news',
pathProperty: 'page-path'
})
)
// ms.env('DEBUG', '*metalsmith*')
ms.build(function (err, files) {
if (err) { throw err }
})
if (options.watch) {
ms.use(watch({
paths: {
/* eslint no-template-curly-in-string: 0 */
'${source}/**/*': '{**/*.hbs,**/*.js,**/*.md,**/*.svg}',
'scss/**/*': '{main.scss,**/*.hbs,**/*.md}',
'layouts/**/*': '**/*.hbs',
'locales/**/*': '**/*.hbs'
},
livereload: true
}))
browserSync.init({
port: 8080,
server: dest,
watch: true,
open: false
})
} else {
ms.use(function (files) {
const out = Object.values(files).filter(file => file.title).map(f => [f.path, f.title, f.description, f.excerpt || ''])
out.forEach(o => console.log(o.join(',')))
})
}