forked from galaxyproject/training-material
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.coffee
107 lines (99 loc) · 3.46 KB
/
build.coffee
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
# Build with Metalsmith
metalsmith = require('metalsmith')
set_metadata_defaults = (files, metalsmith, done) ->
# Simple way to apply metadata defaults
for k, v of files
# Autotoc defaults to true
# Set domain templates
if 'topic' in v.collection
files[k].layout = 'home.pug' if files[k].layout == undefined
files[k].autotoc = false if files[k].autotoc == undefined
else if 'tutorials' in v.collection
files[k].layout = 'default.pug' if files[k].layout == undefined
files[k].autotoc = false if files[k].autotoc == undefined
else if 'slides' in v.collection
files[k].layout = 'default.pug' if files[k].layout == undefined
files[k].autotoc = false if files[k].autotoc == undefined
else
files[k].autotoc = true if files[k].autotoc == undefined
done()
# Extend `marked.Renderer` to increase all heading levels by 1 since we reserve
# h1 for the page title. Will be passed to `metalsmith-markdown` plugin.
marked = require("marked")
class Renderer extends marked.Renderer
heading: ( text, level, raw ) =>
super( text, level + 1, raw )
table: (header, body) =>
return """<table class="table table-striped">
<thead>
#{header}
</thead>
<tbody>
#{body}
</tbody>
</table>"""
image: (href, title, text) =>
out = '<img class="img-responsive" src="' + href + '" alt="' + text + '"'
if title
out += ' title="' + title + '"'
out += '/>'
return out
timer = require( "metalsmith-timer" )
ms = metalsmith(__dirname)
.source('topics')
.use require('metalsmith-metadata')
site: "_config.yaml"
.use timer 'metalsmith-metadata'
.use require('metalsmith-collections')
topics:
pattern: "*/metadata.yaml"
tutorials:
pattern: "*/tutorials/*/tutorial.md"
tutorials:
pattern: "*/tutorials/*/slides/slides.html" # Move to .md?
slides:
pattern: "*/slides/index.html" #Move to .md?
.use set_metadata_defaults
.use timer 'set_metadata_defaults'
.use timer 'metalsmith-collections'
.use require('metalsmith-markdown')
gfm: true
renderer: new Renderer()
.use timer 'metalsmith-markdown'
.use require('metalsmith-autotoc')
selector: "h2, h3, h4"
.use timer 'metalsmith-autotoc'
.use require('metalsmith-alias')()
.use timer 'metalsmith-alias'
.use require('metalsmith-filepath')
absolute: true
permalinks: true
.use timer 'metalsmith-filepath'
.use require('metalsmith-layouts')
engine: "pug"
cache: true
default: "default.pug"
pattern: "**/*.html"
helpers:
moment: require('moment')
marked: require('marked')
_: require('lodash')
.use timer 'metalsmith-layouts'
.use require('metalsmith-assets')
source: 'assets'
destination: ''
.use timer 'metalsmith-assets'
.use require('metalsmith-less')()
.use timer 'metalsmith-less'
argv = require('minimist')(process.argv.slice(2))
if argv['serve']
ms.use( require('metalsmith-serve')( { port: 8080 } ) )
if argv['check']
ms.use require('metalsmith-broken-link-checker')
allowRedirects: true
warn: true
ms.build (e) ->
if e
throw e
else
console.log("Done")