-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbulbofile.js
130 lines (114 loc) · 3.67 KB
/
bulbofile.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
const bulbo = require('bulbo')
const asset = bulbo.asset
const path = require('path')
const frontMatter = require('gulp-front-matter')
const nunjucks = require('gulp-nunjucks')
const markdown = require('gulp-markdown')
const wrapper = require('layout-wrapper')
const accumulate = require('vinyl-accumulate')
const branch = require('branch-pipe')
const data = {
orgName: 'Japan Node.js Association',
pages: require('./pages'),
layoutDir: path.join(__dirname, 'source', 'layout'),
partialsDir: path.join(__dirname, 'source', 'layout', 'partials'),
// file を受け取って root への相対パスを返す関数
basepath: file => path.dirname(path.relative(file.relative, ''))
}
require('nunjucks').configure().addFilter('date', require('nunjucks-date'))
bulbo.dest('build') // Sets the destination
bulbo.port(3100) // Sets the dev server's port
bulbo.base('source')
bulbo.loggerTitle('nodejsjp')
const layout = defaultLayout => wrapper.nunjucks({
data,
defaultLayout,
layout: 'source/layout',
extname: '.njk'
})
asset('source/**/*.md', '!source/{events,jobs,news}/**/*')
.watch('source/**/*.{md,njk}')
.pipe(frontMatter({property: 'fm'}))
.pipe(nunjucks.compile(data))
.pipe(markdown())
.pipe(layout('default'))
// Index page
asset('source/events/**/*.md')
.watch('source/**/*.{md,njk}')
.pipe(frontMatter({property: 'fm'}))
.pipe(markdown())
.pipe(accumulate('index.html', {
debounce: true,
sort: (x, y) => y.fm.date[0].valueOf() - x.fm.date[0].valueOf(),
filter: (x) => x.fm.date[0].valueOf() > Date.now() // filter the past events
}))
.pipe(layout('index'))
// Event pages
asset('source/events/**/*.md')
.watch('source/**/*.{md,njk}')
.pipe(frontMatter({property: 'fm'}))
.pipe(markdown())
.pipe(branch.obj(src => [
src
.pipe(accumulate('events.html', {
debounce: true,
sort: (x, y) => y.fm.date[0].valueOf() - x.fm.date[0].valueOf()
}))
.pipe(layout('event-index')), // Event index page
src
.pipe(layout('event')) // Single event page
]))
// News pages
asset('source/news/**/*.md')
.watch('source/**/*.{md,njk}')
.pipe(frontMatter({property: 'fm'}))
.pipe(markdown())
.pipe(branch.obj(src => [
src
.pipe(accumulate('news.html', {
debounce: true,
sort: (x, y) => y.fm.date.valueOf() - x.fm.date.valueOf()
}))
.pipe(layout('news-index')), // News index page
src
.pipe(layout('news')) // Single news page
]))
/**
* 求人の掲載日の unixtime を返す
* @param {Vinyl} file
* @return {number}
*/
const postedAt = file => file.fm.postedAt ? file.fm.postedAt.valueOf() : 0
// 各スポンサークラスの重み付け
const classWeight = { platinum: 4, gold: 3, silver: 2, bronze: 1, venue: 0 }
/**
* 求人のクラスの重み付けを返す
* @param {Vinyl} file
* @return {number}
*/
const getClassWeight = file => classWeight[file.fm.class] || 0
/**
* ジョブボードのソート関数
* class (platinum/gold/silver/bronze/venue) で並べた上で掲載順で並べる
*/
const jobboardSort = (x, y) => getClassWeight(y) - getClassWeight(x) || postedAt(x) - postedAt(y)
// Jobboard pages
asset('source/jobs/2018/*.md')
.watch('source/**/*.{md,njk}')
.pipe(frontMatter({property: 'fm'}))
.pipe(markdown())
.pipe(branch.obj(src => [
src
.pipe(accumulate('jobboard.html', {
debounce: true,
sort: jobboardSort
}))
.pipe(layout('jobboard')), // Job index page
src
.pipe(layout('job')) // Single job page
]))
asset('source/css/*.css')
asset('source/images/**/*.{png,svg,jpg,jpeg,gif}')
asset('source/pdfs/**/*.pdf')
// Old site is available under http://nodejs.jp/old/
asset('./old/*.*').base('./')