forked from jsdoc/jsdoc.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
136 lines (120 loc) · 3.93 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
124
125
126
127
128
129
130
131
132
133
134
135
136
'use strict';
var beautify = require('metalsmith-beautify');
var connect = require('gulp-connect');
var gulp = require('gulp');
var headings = require('metalsmith-headings');
var markdown = require('metalsmith-markdown');
var marked = require('metalsmith-markdown/node_modules/marked');
var Metalsmith = require('metalsmith');
var minimist = require('minimist');
var path = require('path');
var plugins = require('./lib/plugins');
var util = require('util');
// file extensions to clean up from the destination path
var CLEANUP_EXTENSIONS = ['html'];
// location for output files
var OUTPUT_PATH = '.';
// location of content files
var SOURCE_PATH = 'content/en';
// heading levels to include in the per-page TOC
var TOC_HEADINGS = ['h2, h3'];
// location of Swig views
var VIEW_PATH = path.join(__dirname, 'views');
var knownCliOptions = {
string: 'port',
default: {
port: '7878'
}
};
var cliOptions = minimist(process.argv.slice(2), knownCliOptions);
var swigOptions = {
basepath: VIEW_PATH,
locals: require('./lib/locals')
};
var swigViews = {
index: 'index.swig',
page: 'page.swig',
redirect: 'redirect.swig'
};
// for debugging, because `console` isn't available during a Metalsmith run
global.log = function log() {
console.warn.apply(null, arguments);
};
function markedFactory() {
var renderer = new marked.Renderer();
renderer.code = function(code, language) {
language = language ? (' lang-' + language) : '';
return util.format('<pre class="prettyprint%s"><code>%s\n</code></pre>', language, code);
};
renderer.paragraph = function(text) {
// Swig tags aren't paragraphs
if (text.match(/^\s*\{\%[^%]+\%\}\s*$/)) {
return text;
}
return '<p>' + text + '</p>\n';
};
return renderer;
}
gulp.task('html', function(cb) {
return new Metalsmith(__dirname)
// basic options
.clean(false)
.source(SOURCE_PATH)
.destination(OUTPUT_PATH)
// plugins
.use(plugins.removeFiles({
target: OUTPUT_PATH,
extensions: CLEANUP_EXTENSIONS
}))
.use(plugins.metadata({
destination: OUTPUT_PATH,
tocData: require('./data/toc-data.json')
}))
.use(markdown({
gfm: true,
renderer: markedFactory(),
smartypants: false,
tables: true
}))
.use(plugins.configureSwig(swigViews, swigOptions))
.use(headings({
// use a single jQuery selector so we get all the headings in order
selectors: [TOC_HEADINGS.join(', ')]
}))
.use(plugins.buildHeadingTree(TOC_HEADINGS))
.use(plugins.addTemplateName())
.use(plugins.addJsdocTagMetadata())
.use(plugins.adjustMetadata())
.use(plugins.swig(swigOptions))
.use(plugins.buildRedirects(require('./data/redirects.json')))
.use(plugins.copyStaticFile({
source: path.join(__dirname, 'bower_components/html5shiv/dist/html5shiv.min.js'),
destination: path.join(__dirname, 'scripts/html5shiv.min.js')
}))
.use(plugins.copyStaticFile({
source: path.join(__dirname,
'bower_components/html5shiv/dist/html5shiv-printshiv.min.js'),
destination: path.join(__dirname, 'scripts/html5shiv-printshiv.min.js')
}))
/*eslint camelcase: 0 */
.use(beautify({
css: false,
html: {
indent_char: ' ',
indent_size: 2,
// js-beautify ignores the value 0 because it's falsy
max_preserve_newlines: 0.1
},
js: false
}))
// go!
.build(cb);
});
gulp.task('server', function() {
connect.server({
port: cliOptions.port,
root: path.resolve(__dirname, OUTPUT_PATH)
});
});
gulp.task('preview', ['html', 'server']);
gulp.task('default', ['html']);