Skip to content

Commit 6e37d55

Browse files
kt3khiroppy
authored andcommitted
refactor: use branch-pipe
1 parent 1af9ed1 commit 6e37d55

4 files changed

Lines changed: 49 additions & 40 deletions

File tree

bulbofile.js

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const nunjucks = require('gulp-nunjucks')
77
const marked = require('gulp-marked')
88
const wrapper = require('layout-wrapper')
99
const accumulate = require('vinyl-accumulate')
10+
const branch = require('branch-pipe')
1011

1112
const data = {
1213
orgName: 'Node.js 日本ユーザーグループ',
@@ -49,59 +50,53 @@ asset('source/events/**/*.md')
4950
}))
5051
.pipe(layout('index'))
5152

52-
// Event index pages
53+
// Event pages
5354
asset('source/events/**/*.md')
5455
.watch('source/**/*.{md,njk}')
5556
.pipe(frontMatter({property: 'fm'}))
5657
.pipe(marked())
57-
.pipe(accumulate('events.html', {
58-
debounce: true,
59-
sort: (x, y) => y.fm.date[0].valueOf() - x.fm.date[0].valueOf()
60-
}))
61-
.pipe(layout('event-index'))
58+
.pipe(branch.obj(src => [
59+
src
60+
.pipe(accumulate('events.html', {
61+
debounce: true,
62+
sort: (x, y) => y.fm.date[0].valueOf() - x.fm.date[0].valueOf()
63+
}))
64+
.pipe(layout('event-index')), // Event index page
65+
src
66+
.pipe(layout('event')) // Single event page
67+
]))
6268

63-
// Single event page
64-
asset('source/events/**/*.md')
65-
.watch('source/**/*.{md,njk}')
66-
.pipe(frontMatter({property: 'fm'}))
67-
.pipe(marked())
68-
.pipe(layout('event'))
69-
70-
// News index page
69+
// News pages
7170
asset('source/news/**/*.md')
7271
.watch('source/**/*.{md,njk}')
7372
.pipe(frontMatter({property: 'fm'}))
7473
.pipe(marked())
75-
.pipe(accumulate('news.html', {
76-
debounce: true,
77-
sort: (x, y) => y.fm.date.valueOf() - x.fm.date.valueOf()
78-
}))
79-
.pipe(layout('news-index'))
80-
81-
// Single news pages
82-
asset('source/news/**/*.md')
83-
.watch('source/**/*.{md,njk}')
84-
.pipe(frontMatter({property: 'fm'}))
85-
.pipe(marked())
86-
.pipe(layout('news'))
87-
88-
// Job index page
89-
asset('source/jobs/**/*.md')
90-
.watch('source/**/*.{md,njk}')
91-
.pipe(frontMatter({property: 'fm'}))
92-
.pipe(marked())
93-
.pipe(accumulate('jobboard.html', {
94-
debounce: true,
95-
sort: (x, y) => y.fm.postedAt.valueOf() - x.fm.postedAt.valueOf()
96-
}))
97-
.pipe(layout('jobboard'))
74+
.pipe(branch.obj(src => [
75+
src
76+
.pipe(accumulate('news.html', {
77+
debounce: true,
78+
sort: (x, y) => y.fm.date.valueOf() - x.fm.date.valueOf()
79+
}))
80+
.pipe(layout('news-index')), // News index page
81+
src
82+
.pipe(layout('news')) // Single news page
83+
]))
9884

99-
// Single job page
85+
// Jobboard pages
10086
asset('source/jobs/**/*.md')
10187
.watch('source/**/*.{md,njk}')
10288
.pipe(frontMatter({property: 'fm'}))
10389
.pipe(marked())
104-
.pipe(layout('job'))
90+
.pipe(branch.obj(src => [
91+
src
92+
.pipe(accumulate('jobboard.html', {
93+
debounce: true,
94+
sort: (x, y) => y.fm.postedAt.valueOf() - x.fm.postedAt.valueOf()
95+
}))
96+
.pipe(layout('jobboard')), // Job index page
97+
src
98+
.pipe(layout('job')) // Single job page
99+
]))
105100

106101
asset('source/css/*.css')
107102
asset('source/images/**/*.{png,svg,jpg,jpeg,gif}')

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"vinyl-accumulate": "^1.4.1"
4040
},
4141
"devDependencies": {
42+
"branch-pipe": "^1.0.1",
4243
"rimraf": "^2.5.4"
4344
}
4445
}

source/layout/event-index.njk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
{{ date | date('YYYY年MM月DD日') }}
1515
{% endfor %}
1616
{% if event.fm.image %}
17-
<p><a href="{{ basepath(file) }}{{ event.relative }}"><img src="{{ event.fm.image }}" /></a></p>
17+
<p><a href="{{ basepath(file) }}/{{ event.relative }}"><img src="{{ event.fm.image }}" /></a></p>
1818
{% endif %}
1919
</ul>
2020
{% endfor %}

yarn.lock

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,13 @@ braces@^1.8.2:
167167
preserve "^0.2.0"
168168
repeat-element "^1.1.2"
169169

170+
branch-pipe@^1.0.1:
171+
version "1.0.1"
172+
resolved "https://registry.yarnpkg.com/branch-pipe/-/branch-pipe-1.0.1.tgz#f1a1903d15cf8421658ead586c062db7c8dc253d"
173+
dependencies:
174+
duplexer2 "^0.1.4"
175+
merge-stream "^1.0.1"
176+
170177
buffer-shims@^1.0.0:
171178
version "1.0.0"
172179
resolved "https://registry.yarnpkg.com/buffer-shims/-/buffer-shims-1.0.0.tgz#9978ce317388c649ad8793028c3477ef044a8b51"
@@ -1427,6 +1434,12 @@ merge-stream@^1.0.0:
14271434
dependencies:
14281435
readable-stream "^2.0.1"
14291436

1437+
merge-stream@^1.0.1:
1438+
version "1.0.1"
1439+
resolved "https://registry.yarnpkg.com/merge-stream/-/merge-stream-1.0.1.tgz#4041202d508a342ba00174008df0c251b8c135e1"
1440+
dependencies:
1441+
readable-stream "^2.0.1"
1442+
14301443
micromatch@^2.1.5, micromatch@^2.3.7:
14311444
version "2.3.11"
14321445
resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-2.3.11.tgz#86677c97d1720b363431d04d0d15293bd38c1565"

0 commit comments

Comments
 (0)