-
-
Notifications
You must be signed in to change notification settings - Fork 128
/
Copy pathhelpers.js
39 lines (34 loc) · 993 Bytes
/
helpers.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
// configure markdown-it
const transformer = require('jstransformer')
const { _tr: mdTransformer } = transformer(require('jstransformer-markdown-it'))
const config = {
typographer: true,
html: true
}
// monkey-patch render function to pass custom options
const { render: renderMd } = mdTransformer
mdTransformer.render = str => renderMd(str, config)
const slugify = str => str.toLowerCase().replace(/\W/, '-')
const truncate = (str, wordCount) => {
const words = str.trim().split(/\s(?![^\[]*\])/g)
const head = words.splice(0, wordCount).join(' ')
const tail = words.join(' ')
return [head, tail]
}
const assetPath = path => {
let revs
try {
revs = require('./rev-manifest.json')
} catch (error) {}
return `${(revs && revs[path]) || path}`
}
const assetUrl = (path, protocol = 'https') => {
return `${protocol}://bitcoindevlist.com${assetPath(path)}`
}
module.exports = {
slugify,
truncate,
assetUrl,
assetPath,
renderMarkdown: mdTransformer.render
}