UNPKG

879 Btext/coffeescriptView Raw
1_ = require('lodash')
2dynamic = require('metalsmith-dynamic')
3
4exports.getValue = (value, restArgs...) ->
5 if typeof value is 'function'
6 value = value(restArgs...)
7 return value
8
9exports.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
16exports.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
24exports.replacePlaceholders = dynamic.util.replacePlaceholders
25
26exports.refToFilename = (ref, ext, addExt) ->
27 if ref is ''
28 ref = 'index'
29 return dynamic.util.refToFilename(ref, ext, addExt)
30
31exports.filenameToRef = (filename) ->
32 [ ref, ext ] = dynamic.util.filenameToRef(filename)
33 if ref is 'index'
34 ref = ''
35 return [ ref, ext ]