-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnuxt.config.js
606 lines (521 loc) · 20 KB
/
nuxt.config.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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
const pkg = require('./package')
// note: nuxt requires Node 8+ to run properly
// dynamic imports for SSR
import Cytosis from './other/cytosis'
import axios from 'axios'
// import { loadNews } from './other/loaders'
// https://github.com/joshbuchea/HEAD https://gethead.info/
// these are the default social sharing items
// make sure to use the Head component for generated data
const site_policy = '1.0.3'
// 1.0.3: added Hot Jar and improved granularity; still probably needs a lot of tweaking
const site_ga = 'UA-109657404-1'
const site_url = 'https://phage.directory'
const site_name = 'Phage Directory';
const site_twitter = '@phagedirectory';
const site_twitter_creator = '@yawnxyz';
const site_color = '#374F6A';
const site_title = 'Phage Directory';
const site_description = 'Phage Directory curates a database of phage labs, phages, and host strains to advance research and phage therapy.';
// const site_ico = '/ico_dull.png';
const site_ico = '/_ico.png';
const site_image = '/share_img.png';
const site_search = 'index,follow';
const site_author = 'Jan Zheng';
const page_name = ''; // placeholder for the copy+paste
const site_fb = '172737416727733'; // buildAtl fb id
const airtable_api = 'keyAe6M1KoPfg25aO'; // [email protected] handler
const airtable_base = 'appSCAap8SWbFRtu0';
const analyze = false; // analyzer (webpack; turn off for prod)
const offline = false;
let mode = 'universal'
// 'spa' loads airtable dynamically
// 'static' only generates once / use npm run generate
// const mode = 'universal' // loads airtable during build-time only (any changes to airtable won't be reflected live)
if (process.env.NODE_ENV == 'spa') {
console.log('RUNNING IN SPA MODE')
mode = 'spa'
}
const site_static = true; // if set to true, the client will never pull data
let site_routes; // used for the generate process to save on airtable pulls
// load cytosis data here, for easier generation
const initData = async function() {
console.log('initData loading ...')
// use sparingly; this data makes it into all generated html files
let cytosis = await new Cytosis({
airKey: airtable_api,
airBase: airtable_base,
tableQuery: '_all',
})
console.log('initData loaded!')
return cytosis
}
// In your `feed` array:
const createFeed = async function(feed) {
feed.options = {
title: 'My blog',
link: 'https://lichter.io/feed.xml',
description: 'This is my personal feed!'
}
const posts = await (axios.get('https://blog-api.lichter.io/posts')).data
posts.forEach(post => {
feed.addItem({
title: post.title,
id: post.url,
link: post.url,
description: post.description,
content: post.content
})
})
feed.addCategory('Nuxt.js')
feed.addContributor({
name: 'Alexander Lichter',
email: '[email protected]',
link: 'https://lichter.io/'
})
}
module.exports = (async function() {
let site_data
if (mode == 'universal')
site_data = await initData()
// console.log('site_data:', site_data)
let obj = {
// export default {
// mode: 'universal', // use this for deployment; need to rebuild the site every time airtable content changes
mode: mode, // for development, or for real-time airtable changes
env: {
mode: mode,
site_fb: site_fb,
airtable_api: airtable_api,
airtable_base: airtable_base,
site_policy: site_policy,
ext_handler: 'https://wt-ece6cabd401b68e3fc2743969a9c99f0-0.sandbox.auth0-extend.com/phdir-input',
site_data: site_data,
site_static: site_static,
},
render: {
// https://nuxtjs.org/api/configuration-render#resourcehints
// disable prefetch of all the pages; saves bg download data
// resourceHints: false,
// Content-Security-Policy
// https://nuxtjs.org/api/configuration-render#csp
// csp: {
// hashAlgorithm: 'sha256',
// allowedSources: undefined,
// policies: undefined
// }
},
/*
Headers of the page
'hid' is a 'head identifier' and used as a unique key
*/
head: {
title: site_title,
meta: [
{ charset: 'utf-8' },
// { name: 'viewport', content: 'width=device-width, initial-scale=1, maximum-scale=1' }, // max-scale prevents auto-zoom on mobile, may prevent zoom
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
{ hid: 'description', name: 'description', content: site_description },
{ hid: 'theme-color', name: 'theme-color', content: site_color },
{ hid: 'search-google', name: 'robots', content: site_search },
{ hid: 'search-robots', name: 'googlebot', content: site_search },
// { hid: 'nositelinkssearchbox', name: 'google', content: 'nositelinkssearchbox' },
// { hid: 'notranslate', name: 'google', content: 'notranslate' },
// Page-Specific
// Facebook
// <meta property="fb:app_id" content="123456789">
{ hid: 'fb-app_id', property: 'fb:app_id', content: site_fb },
// <meta property="og:url" content="http://example.com/page.html">
{ hid: 'og-url', property: 'og:url', content: site_url + '/' + page_name },
// <meta property="og:type" content="website">
{ hid: 'og-type', property: 'og:type', content: 'website' },
// <meta property="og:title" content="Content Title">
{ hid: 'og-title', property: 'og:title', content: site_title },
// <meta property="og:image" content="http://example.com/image.jpg">
// FB & Twitter work best with: 1200 X 675
{ hid: 'og-image', property: 'og:image', content: site_url + site_image },
// <meta property="og:description" content="Description Here">
{ hid: 'og-description', property: 'og:description', content: site_description },
// <meta property="og:site_name" content="Site Name">
{ hid: 'og-site_name', property: 'og:site_name', content: site_name },
// <meta property="og:locale" content="en_US">
{ hid: 'og-locale', property: 'og:locale', content: 'en_US' },
// <meta property="article:author" content="">
{ hid: 'article-author', property: 'article:author', content: site_author },
// Twitter Card
// <meta name="twitter:card" content="summary"> > summary or summary_large_image
{ hid: 'twitter-card', property: 'twitter:card', content: 'summary' },
// <meta name="twitter:site" content="@site_account">
{ hid: 'twitter-site', property: 'twitter:site', content: site_twitter },
// <meta name="twitter:creator" content="@individual_account">
{ hid: 'twitter-creator', property: 'twitter:creator', content: site_twitter_creator },
// <meta name="twitter:url" content="http://example.com/page.html">
{ hid: 'twitter-url', property: 'twitter:url', content: site_url + '/' + page_name },
// <meta name="twitter:title" content="Content Title">
{ hid: 'twitter-title', property: 'twitter:title', content: site_title },
// <meta name="twitter:description" content="Content description less than 200 characters">
{ hid: 'twitter-description', property: 'twitter:description', content: site_description },
// <meta name="twitter:image" content="http://example.com/image.jpg">
{ hid: 'twitter-image', property: 'twitter:image', content: site_url + site_image },
],
link: [
// <!-- Helps prevent duplicate content issues -->
// <link rel="canonical" href="http://example.com/">
{ hid: 'canonical', rel: 'canonical', href: site_url+'/' },
{ rel: 'icon', type: 'image/png', href: site_ico }, // <link rel="icon" sizes="192x192" href="/path/to/icon.png">
{ rel: 'apple-touch-icon', href: site_ico }, // default resolution is 192x192 <link rel="apple-touch-icon" href="/path/to/apple-touch-icon.png">
{ rel: 'mask-icon', href: site_ico, color: site_color}, // <link rel="mask-icon" href="/path/to/icon.svg" color="blue"> <!-- Safari Pinned Tab Icon -->
// { rel: 'stylesheet', href: 'https://fonts.googleapis.com/css?family=PT+Serif' }
],
},
/*
** Customize the progress bar color
*/
loading: { color: site_color },
/*
** Build configuration
*/
plugins: [
// '~plugins/filters.js',nuxtjs/google-tag-manager
// '~plugins/vue-highlightjs.js',
// { src: '~/plugins/plugintest.js', ssr: false }
{ src: '~/plugins/policy.js', ssr: false },
{ src: '~/plugins/hotjar.js', ssr: false }, // need to link this to policy
{ src: '~/plugins/mixpanel.js', ssr: false },
{ src: '~/plugins/markdownit.js' },
{ src: '~/plugins/cytosis.js' },
{ src: '~/plugins/date.js' },
{ src: '~/plugins/twitter.js', ssr: false },
{ src: '~/plugins/disqus.js', ssr: false },
],
modules: [
// '@nuxtjs/font-awesome',
['@nuxtjs/google-analytics', {
id: site_ga,
// disabled: true // gdpr, policy.js enables it: https://medium.com/dailyjs/google-analytics-gdpr-and-vuejs-e1bd6affd2b4
}],
['@nuxtjs/google-tag-manager', {
id: 'GTM-WCR3X43'
}],
'@nuxtjs/pwa',
],
manifest: {
name: 'Phage Directory',
short_name: 'phagedirectory',
display: 'standalone',
start_url: 'https://phage.directory/',
theme_color: site_color,
background_color: '#FFFFFF',
lang: 'en',
// icons: PWAIcons
},
workbox: {
globPatterns: ['**/*.{js,css}', '**/img/*'],
offlinePage: '/404.html',
generate: {
fallback: true
},
// this breaks SPA mode, and is super aggressive, but makes offline mode work really well
// runtimeCaching: [
// {
// urlPattern: 'https://api.airtable.com/v0/appSCAap8SWbFRtu0/.*',
// handler: 'cacheFirst',
// method: 'GET',
// strategyOptions: {cacheableResponse: {statuses: [0, 200]}}
// },
// // {
// // urlPattern: 'https://fonts.googleapis.com/.*',
// // handler: 'cacheFirst',
// // method: 'GET',
// // strategyOptions: {cacheableResponse: {statuses: [0, 200]}}
// // },
// // {
// // urlPattern: 'https://fonts.gstatic.com/.*',
// // handler: 'cacheFirst',
// // method: 'GET',
// // strategyOptions: {cacheableResponse: {statuses: [0, 200]}}
// // },
// ]
},
build: {
// helps cache busting
filenames: {
app: ({ isDev }) => isDev ? '[name].js' : '[chunkhash].js',
// chunk: ({ isDev }) => isDev ? '[name].js' : '[chunkhash].js',
css: ({ isDev }) => isDev ? '[name].css' : '[contenthash].css'
},
// https://willbrowning.me/reducing-the-vendor-bundle-size-in-nuxt-js/
// analyze: analyze, use --analyze instead for visualizer
minimize: true,
// cache: true,
extractCSS: true, // moves css out to its own file in gen
optimizeCSS: true,
// splitChunks: {
// layouts: true
// },
babel: {
sourceType: "unambiguous",
presets: [
['@babel/preset-env', {
// debug: true,
useBuiltIns: 'usage',
targets: {
"browsers": ["> 1%", "ie >= 11", "not ie <= 8"]
// "browsers": ["> 1%", "last 2 versions", "ie >= 11", "not ie <= 8"]
}
}]
],
plugins: ['@babel/plugin-transform-arrow-functions', '@babel/plugin-syntax-dynamic-import', '@babel/plugin-transform-typeof-symbol', '@babel/plugin-transform-runtime'],
},
// explicitly transpile these
transpile: ['cytosis', 'vuex-cache', 'markdownit', 'markdown-it-attrs'],
// transpile: ['cytosis', 'vuex-cache', 'markdownit'],
// extend(config, ctx) {
// // Run ESLint on save
// if (ctx.isDev && ctx.isClient) {
// config.module.rules.push({
// enforce: "pre",
// test: /\.(js|vue)$/,
// loader: "eslint-loader",
// exclude: /(node_modules)/
// })
// }
// }
},
css: [
// coeur style guide
// '@/assets/css/settings.scss',
// '@/node_modules/coeur/styles/index.scss', // this imports EVERYTHING; is going to be huge; overrides 'settings'
// main project styles
'@/assets/css/main.scss'
],
router: {
// middleware: 'pageload', // middleware added on the template
extendRoutes (routes, resolve) {
// capsid should resolve anything from phages
// to people and orgs; easier w/ a uniform id resolver
routes.push(
// {
// name: 'capsid',
// path: '/d/:capsid',
// component: resolve(__dirname, 'pages/Dir.vue')
// },
{
name: 'capsid',
path: '/capsid',
component: resolve(__dirname, 'pages/capsidlist.vue')
},
{
// always shows the latest capsid; GOES BEFORE capsidIssue / capsid/:slug
name: 'capsidLatest',
path: '/capsid/latest',
component: resolve(__dirname, 'pages/capsidlatest.vue')
},
{
// opens each issue separately, good for deeplinking, possibly comments
name: 'capsidIssue',
path: '/capsid/:slug',
component: resolve(__dirname, 'pages/capsidissue.vue')
},
{
// email-generated issue to be pasted into mailchimp
name: 'capsidEmail',
path: '/capsidemail/:slug',
component: resolve(__dirname, 'pages/capsidemail.vue')
},
{
name: 'search',
path: '/search/:searchstr',
component: resolve(__dirname, 'pages/directory.vue')
},
{
name: 'phages',
path: '/phages',
component: resolve(__dirname, 'pages/directory.vue')
},
{
name: 'hosts',
path: '/hosts',
component: resolve(__dirname, 'pages/directory.vue')
},
{
name: 'organisms',
path: '/organisms',
component: resolve(__dirname, 'pages/directory.vue')
},
{
name: 'diseases',
path: '/diseases',
component: resolve(__dirname, 'pages/directory.vue')
},
{
name: 'antibiotics',
path: '/antibiotics',
component: resolve(__dirname, 'pages/directory.vue')
},
// {
// name: 'orgs',
// path: '/orgs',
// component: resolve(__dirname, 'pages/directory.vue')
// },
{
name: 'labs',
path: '/labs',
component: resolve(__dirname, 'pages/directory.vue')
},
{
// opens each issue separately, good for deeplinking, possibly comments
name: 'jobs',
path: '/jobs',
component: resolve(__dirname, 'pages/joblist.vue')
},
{
// opens each issue separately, good for deeplinking, possibly comments
name: 'job',
path: '/jobs/:slug',
component: resolve(__dirname, 'pages/jobpage.vue')
},
// {
// name: 'people',
// path: '/people',
// component: resolve(__dirname, 'pages/directory.vue')
// },
// {
// name: 'apply',
// path: '/projects/:id/apply',
// component: resolve(__dirname, 'pages/ApplyPage.vue')
// },
// news alerts
// {
// name: 'alerts',
// path: '/alerts/:id',
// component: resolve(__dirname, 'pages/alerts.vue')
// },
// blog / news / 'viral' newsletter; resolves to generic Blog page
// {
// name: 'Update.item',
// path: '/updates/:slug',
// component: resolve(__dirname, 'pages/Updates.vue')
// },
// { // split up into the news component
// name: 'News',
// path: '/news',
// component: resolve(__dirname, 'pages/Blog.vue')
// },
// {
// name: 'News.item',
// path: '/news/:slug',
// component: resolve(__dirname, 'pages/Blog.vue')
// },
// {
// name: 'Updates',
// path: '/updates',
// component: resolve(__dirname, 'pages/Blog.vue')
// },
// {
// name: 'Updates.item',
// path: '/updates/:slug',
// component: resolve(__dirname, 'pages/updates.vue')
// },
// other resolvers
{
name: 'questions',
path: '/questions',
component: resolve(__dirname, 'pages/feedback.vue')
},
{
name: 'legal',
path: '/legal',
component: resolve(__dirname, 'pages/policies.vue')
},
// experimental
{
name: 'phagefutures-alt',
path: '/phage-futures',
component: resolve(__dirname, 'pages/phagefutures.vue')
},
{
name: 'phagefutures-agenda',
path: '/phagefutures/agenda',
component: resolve(__dirname, 'pages/phagefutures.vue')
},
{
name: 'phagefutures-posters',
path: '/phagefutures/posters',
component: resolve(__dirname, 'pages/phagefutures.vue')
},
{
name: 'phagefutures-about',
path: '/phagefutures/about',
component: resolve(__dirname, 'pages/phagefutures.vue')
},
// {
// name: 'phagefutures-feedback',
// path: '/phage-futures/feedback',
// component: resolve(__dirname, 'pages/phagefutures.vue')
// },
// {
// name: 'phagefutures-agenda',
// path: '/phagefutures/agenda',
// component: resolve(__dirname, 'pages/phagefutures.vue')
// },
// {
// name: 'phagefutures-posters',
// path: '/phagefutures/posters',
// component: resolve(__dirname, 'pages/phagefutures.vue')
// },
// {
// name: 'phagefutures-about',
// path: '/phagefutures/about',
// component: resolve(__dirname, 'pages/phagefutures.vue')
// },
// {
// name: 'phagefutures-feedback',
// path: '/phagefutures/feedback',
// component: resolve(__dirname, 'pages/phagefutures.vue')
// },
)
},
},
generate: {
interval: 500, // slow down api calls // https://nuxtjs.org/api/configuration-generate/
// fallback: false, // if you want to use '404.html' — for surge, use false if you want to use 200 spa fallback
// concurrency: 1, // reduce server strain
routes: async function (callback) {
const airKey = airtable_api
const airBase = airtable_base
// only generate once
if(!site_routes) {
console.log('[generator]: fetch from cytosis')
site_routes = await new Cytosis({
airKey,
airBase,
tableQuery: '_gen-routes',
caller: 'generator'
})
}
let routeList = []
// build C&T issues
let ctr = 0
for (let capsid of site_routes.tables['C&T']) {
if(capsid.fields['Slug'])
if(ctr > 5) {
break
} else {
console.log('adding Capsid: ', capsid.fields['Slug'])
routeList.push(`/capsid/${capsid.fields['Slug']}`)
ctr = ctr + 1
}
}
// // build Jobs pages
for (let jobs of site_routes.tables['Jobs']) {
if(jobs.fields['Slug'])
routeList.push(`/jobs/${jobs.fields['Slug']}`)
}
console.log('[generator] routes: ', routeList)
callback(null, routeList)
}
}
}
return obj
})()