1 | _ = require('lodash')
|
2 | dynamic = require('metalsmith-dynamic')
|
3 |
|
4 | exports.getValue = (value, restArgs...) ->
|
5 | if typeof value is 'function'
|
6 | value = value(restArgs...)
|
7 | return value
|
8 |
|
9 | exports.extractTitleFromText = (body) ->
|
10 | headings = body
|
11 | .split('\n')
|
12 | .map (s) -> s.trim()
|
13 | .filter (s) -> s[0] is '#'
|
14 | return headings[0]?.replace(/\#+\s?/, '')
|
15 |
|
16 | exports.slugify = (s) ->
|
17 | return '' if not s
|
18 | s.toLowerCase()
|
19 | .replace(/[^a-z0-9]/gi, '-')
|
20 | .replace(/-{2,}/g, '-')
|
21 | .replace(/^-/, '')
|
22 | .replace(/-$/, '')
|
23 |
|
24 | exports.replacePlaceholders = dynamic.util.replacePlaceholders
|
25 |
|
26 | exports.refToFilename = (ref, ext, addExt) ->
|
27 | if ref is ''
|
28 | ref = 'index'
|
29 | return dynamic.util.refToFilename(ref, ext, addExt)
|
30 |
|
31 | exports.filenameToRef = (filename) ->
|
32 | [ ref, ext ] = dynamic.util.filenameToRef(filename)
|
33 | if ref is 'index'
|
34 | ref = ''
|
35 | return [ ref, ext ]
|