Issues (117)

lib/patternlibrary/build-pages.js (1 issue)

Check to flag declared but unused variables

Unused Code Minor
1 1
var fs              = require('fs');
2 1
var mkdirp          = require('mkdirp').sync;
3 1
var path            = require('path');
4 1
var through         = require('through2');
5 1
var vfs             = require('vinyl-fs');
6 1
var glob            = require('glob');
7 1
var globAll         = require('glob-all');
8 1
var extend          = require('extend');
9 1
var fm              = require('front-matter');
10 1
var resolvePath     = require('../util/module-or-process-path');
11 1
var relativeRootUrl = require('../util/relative-root-url');
12 1
var stripAbsolutePath        = require('../util/strip-absolute-path');
13
14
/**
15
 * run doc page building 
16
 * - either by given 'src' option 
17
 * - or through vinyl/gulp filestream
18
 *
19
 * @returns {stream} 
20
 */
21
function buildPages( source, targetdir, rootdir ) {
22 20
	if (!source) {
23 20
		source = this.options.root;
24
	}
25 20
	var fileglob = source;
26
	
27 20
	if ((typeof source == 'string') && fs.statSync(source).isDirectory()) {
28 20
		source = path.join(source, '**/*.{md,markdown,html,hbs,handlebars}');
29 20
    	fileglob = globAll.sync([
30
    		source,
31
    		'!'+path.join(this.options.root,'pl/**/*')
32
    	]);
33
	} else {
34 2
		if (Array.isArray(source)) {
35
			fileglob = globAll.sync(source);
36
		}
37
	}
38 20
	if (!targetdir) {
39 20
		targetdir = this.options.dest;
40
	}
41
    // the main selector are the pattern doc files
42
    // default: [partial-path]/**/*.{md,markdown}
43
    //
44
    // ...but first, (re)set layout and page template 
45
    // just to be sure ^^
46 20
    this.layout       = this.options.gui.layout;
47 20
    this.pagetemplate = this.options.gui.docpage;
48 20
    if (source) {
49 20
        var stream = vfs.src(fileglob)
50
                        .pipe(transformPages.apply(this))
51
        ; 
52
53 20
        return stream;
54
    } else {
55
        return transformPages.apply(this);
56
    }
57
58
    function transformPages(file, enc, cb) {
59 20
        return through.obj(function(file, enc, cb) {
60
        	
61
            // prepare rendering the page...
62 25
            var fileName = path.basename(file.path);
0 ignored issues
show
The variable fileName seems to be never used. Consider removing it.
Loading history...
63 25
            var ext      = path.extname(file.path);
64 25
            var page     = fm(file.contents.toString());
65 25
            var markdown = isMD(file.path);
66
            
67
            // assign page layout
68 25
            var layout = page.attributes.layout || 'default';
69 25
            this.layout = layout;
70
71
            // set the file to page...
72 25
            if (markdown) {
73
                this.pagetemplate = '{__MDBODY__}';
74
            } else {
75 25
                this.pagetemplate = file.path;
76
            }
77
            
78
            // try O:) to normalize file's path
79 25
            var page_filepath = stripAbsolutePath(file.path)
80
                .replace(path.join(this.options.gui.pages, 'pl/'), '')
81
                .replace(path.join(this.options.root, this.options.basepath), '')
82
                .replace(path.join(this.options.gui.pages), '')
83
                .replace(path.join(this.options.root), '')
84
            ;
85
            
86 25
            var page_target = path.join(targetdir, page_filepath).replace(ext, '.html');
87 25
            file.path = page_target;
88
            
89 25
            var data = page.attributes;
90 25
            if (markdown) {
91
            	
92
                var markdownBody = this.markdown.render(page.body);
93
                this.renderpage( file.path, page_target, data, markdownBody);
94
                
95
            } else {
96
            	
97 25
                this.renderpage( file.path, page_target, data);
98
                
99
            }
100
             
101
            
102
            
103 25
            cb();
104
          
105
        }.bind(this));
106
    };
107
}
108
109 1
module.exports = buildPages;
110
111
112
function isMD ( str ) { 
113
	return ( (path.extname( str ) == '.md') || (path.extname( str ) == '.markdown') ); 
114
}