1 |
|
2 | (function() {
|
3 | var _, dynamic,
|
4 | slice = [].slice;
|
5 |
|
6 | _ = require('lodash');
|
7 |
|
8 | dynamic = require('metalsmith-dynamic');
|
9 |
|
10 | exports.getValue = function() {
|
11 | var restArgs, value;
|
12 | value = arguments[0], restArgs = 2 <= arguments.length ? slice.call(arguments, 1) : [];
|
13 | if (typeof value === 'function') {
|
14 | value = value.apply(null, restArgs);
|
15 | }
|
16 | return value;
|
17 | };
|
18 |
|
19 | exports.extractTitleFromText = function(body) {
|
20 | var headings, ref1;
|
21 | headings = body.split('\n').map(function(s) {
|
22 | return s.trim();
|
23 | }).filter(function(s) {
|
24 | return s[0] === '#';
|
25 | });
|
26 | return (ref1 = headings[0]) != null ? ref1.replace(/\#+\s?/, '') : void 0;
|
27 | };
|
28 |
|
29 | exports.slugify = function(s) {
|
30 | if (!s) {
|
31 | return '';
|
32 | }
|
33 | return s.toLowerCase().replace(/[^a-z0-9]/gi, '-').replace(/-{2,}/g, '-').replace(/^-/, '').replace(/-$/, '');
|
34 | };
|
35 |
|
36 | exports.replacePlaceholders = dynamic.util.replacePlaceholders;
|
37 |
|
38 | exports.refToFilename = function(ref, ext, addExt) {
|
39 | if (ref === '') {
|
40 | ref = 'index';
|
41 | }
|
42 | return dynamic.util.refToFilename(ref, ext, addExt);
|
43 | };
|
44 |
|
45 | exports.filenameToRef = function(filename) {
|
46 | var ext, ref, ref1;
|
47 | ref1 = dynamic.util.filenameToRef(filename), ref = ref1[0], ext = ref1[1];
|
48 | if (ref === 'index') {
|
49 | ref = '';
|
50 | }
|
51 | return [ref, ext];
|
52 | };
|
53 |
|
54 | }).call(this);
|