-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmetalsmith.js
76 lines (69 loc) · 1.82 KB
/
metalsmith.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
const metalsmith = require('metalsmith')
const markdown = require('metalsmith-markdown')
const layouts = require('metalsmith-layouts')
const ignore = require('metalsmith-ignore')
const collections = require('metalsmith-collections')
const relative = require('metalsmith-relative')
const marked = require('marked')
const prism = require('prismjs')
const renderer = new marked.Renderer()
// Change the code method to output the same as Prism.js would.
renderer.code = function (code, lang, escaped) {
const codeHighlighted = this.options.highlight(code, lang)
if (!lang) {
return `<pre><code>${codeHighlighted}\n</code></pre>`
}
// e.g. "language-js"
const langClass = this.options.langPrefix + lang
return '<pre class="' + langClass + '"><button class="button button-primary uppercase" data-copy>Copy</button><code class="' + langClass + '">' +
codeHighlighted +
'</code></pre>\n'
}
// Translate marked languages to prism.
var extensions = {
js: 'javascript',
scss: 'css',
html: 'markup',
svg: 'markup'
}
metalsmith(__dirname)
.source('./docs')
.clean(false)
.use(collections({
docs: {
pattern: 'components/*.md',
sortBy: 'priority',
reverse: true
}
}))
.use(relative({
methodName: 'root'
}))
.use(markdown({
gfm: true,
smartypants: true,
renderer: renderer,
langPrefix: 'language-',
highlight: function (code, lang) {
if (!prism.languages.hasOwnProperty(lang)) {
// Default to markup.
lang = extensions[lang] || 'markup'
}
return prism.highlight(code, prism.languages[lang])
}
}))
.use(layouts({
engine: 'jade',
directory: 'docs/layout'
}))
.use(ignore([
'**/.DS_Store',
'layout/**',
'styles/**'
]))
.destination('./public')
.build((err) => {
if (err) {
throw err
}
})