-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
123 lines (115 loc) · 3.35 KB
/
gulpfile.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
const { dest, parallel, series, src } = require('gulp');
const changed = require('gulp-changed');
const concat = require('gulp-concat');
const data = require('gulp-data');
const frontmatter = require('front-matter');
const marked = require('marked');
const print = require('gulp-print').default;
const rename = require('gulp-rename');
const sass = require('gulp-sass')(require('sass'));
const sitemap = require('gulp-sitemap');
const uglify = require('gulp-uglify');
const wrap = require('gulp-wrap');
const path = {
template: 'src/template/',
pages: 'src/pages/',
assets: 'src/assets/',
};
function buildHtml() {
return src(path.pages + 'html/**/*.html')
.pipe(
data(function (file) {
const content = frontmatter(String(file.contents));
file.contents = Buffer.from(content.body);
const fm = { attr: content['attributes'] };
return fm;
})
)
.pipe(wrap({ src: path.template + '_page.html' }))
.pipe(changed('dist'), { hasChanged: changed.compareSha1Digest })
.pipe(dest('dist'))
.pipe(print());
}
function buildTmdbHtml() {
return src(path.pages + 'tmdb/*.md')
.pipe(
data(function (file) {
const content = frontmatter(String(file.contents));
file.contents = Buffer.from(content.body);
const fm = { attr: content['attributes'] };
return fm;
})
)
.pipe(
data(function (file) {
file.contents = Buffer.from(marked.parse(String(file.contents)));
})
)
.pipe(wrap({ src: path.template + '_tmdb.html' }))
.pipe(
rename(function (path) {
path.extname = '.html';
})
)
.pipe(changed('dist/tmdb'), { hasChanged: changed.compareSha1Digest })
.pipe(dest('dist/tmdb'))
.pipe(print());
}
function buildTmdbJson() {
return src(path.pages + 'tmdb/*.md')
.pipe(
data(function (file) {
const content = frontmatter(String(file.contents));
file.contents = Buffer.from(content.body);
const fm = { attr: content['attributes'] };
return fm;
})
)
.pipe(wrap({ src: path.template + '/_tmdb.json' }))
.pipe(concat('db.js', { newLine: ',\r\n' }))
.pipe(
wrap('const db = {\r\n "version":"<%= ver %>",\r\n "data":[\r\n<%= contents %>\r\n ]\r\n};', {
ver: '2015.3.14',
})
)
.pipe(uglify())
.pipe(
rename({
suffix: '.min',
})
)
.pipe(changed('dist/src'), { hasChanged: changed.compareSha1Digest })
.pipe(dest('dist/src'))
.pipe(print());
}
function buildStaticFiles() {
return src(path.assets + 'static/**/*')
.pipe(changed('dist'), { hasChanged: changed.compareSha1Digest })
.pipe(dest('dist'))
.pipe(print());
}
function buildCss() {
return src(path.assets + 'css/tsukikan.scss')
.pipe(sass({ outputStyle: 'compressed' }).on('error', sass.logError))
.pipe(rename('style.min.css'))
.pipe(changed('dist/src'), { hasChanged: changed.compareSha1Digest })
.pipe(dest('dist/src'))
.pipe(print());
}
function buildSitemap() {
return src('dist/**/*.html')
.pipe(
sitemap({
siteUrl: 'https://www.tsukikan.com',
changefreq: 'yearly',
priority: 1.0,
})
)
.pipe(dest('dist'))
.pipe(print());
}
exports.default = series(
parallel(buildHtml, buildTmdbHtml, buildTmdbJson),
parallel(buildCss, buildStaticFiles),
buildSitemap
);