-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
86 lines (78 loc) · 2.14 KB
/
index.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
var options = require('commander')
var nib = require('nib')
var metalsmith = require('metalsmith')
var browserSync = require('metalsmith-browser-sync')
var branch = require('metalsmith-branch')
var markdown = require('metalsmith-markdown')
var fingerprint = require('metalsmith-fingerprint')
var layouts = require('metalsmith-layouts')
var stylus = require('metalsmith-stylus')
var navigation = require('metalsmith-navigation')
var headingsidentifier = require('metalsmith-headings-identifier')
var assets = require('metalsmith-assets')
var addFiles = require('./plugins/add-files')
var browserify = require('./plugins/browserify')
var renderer = require('./plugins/markdown-renderer')
options
.option('-w, --watch', 'Serve and watch files.')
.option('-P, --pretty', 'Compile pretty assets.')
.parse(process.argv)
var js = branch()
.use(browserify({
debug: options.pretty,
entries: ['assets/js/index.js'],
outfile: 'assets/js/index.js',
transforms: ['uglifyify']
}))
var css = branch()
.use(addFiles('assets/css/index.styl'))
.pattern('assets/css/index.styl')
.use(stylus({
compress: !options.pretty,
use: [nib()]
}))
.use(fingerprint({pattern: ['assets/css/index.css']}))
var img = branch()
.use(assets({
source: './assets/img',
destination: './assets/img'
}))
// Proccess Docs files and add the layout
var views = branch('**/*.md')
.use(markdown({
smartypants: true,
gfm: true,
tables: true,
renderer: renderer
}))
.use(headingsidentifier())
.use(navigation({
sidebar: {
sortBy: function (node){ return node && node.position || 999 },
includeDirs: true
}
}))
.use(layouts({
engine: 'jade',
pretty: options.pretty,
directory: './assets',
default: 'layout.jade'
}))
var build = metalsmith(__dirname)
.source('app/docs')
.destination('build')
.use(js)
.use(css)
.use(img)
.use(views)
.use(assets({
source: './assets/statics',
directory: '.'
}))
if (options.watch) build
.destination('.tmp')
.use(browserSync({
server: '.tmp',
files: ['app/docs/**/*', 'assets/**/*']
}))
build.build(function(err){ if (err) throw err; })