-
Notifications
You must be signed in to change notification settings - Fork 260
Expand file tree
/
Copy pathgrunt.js
More file actions
82 lines (70 loc) · 2.08 KB
/
grunt.js
File metadata and controls
82 lines (70 loc) · 2.08 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*jshint node:true */
module.exports = function( grunt ) {
var // modules
pygmentize = require( "pygmentize" ),
// files
pageFiles = grunt.file.expandFiles( "pages/*.html" ),
entryFiles = grunt.file.expandFiles( "entries/*.xml" ),
noteFiles = grunt.file.expandFiles( "notes/*.xml" ),
xmlFiles = [].concat( entryFiles, noteFiles, "cat2tax.xsl", "categories.xml", "entries2html.xsl", "xml2json.xsl" );
grunt.loadNpmTasks( "grunt-clean" );
grunt.loadNpmTasks( "grunt-wordpress" );
grunt.loadNpmTasks( "grunt-jquery-content" );
grunt.initConfig({
clean: {
folder: "dist"
},
lint: {
grunt: "grunt.js"
},
xmllint: {
all: xmlFiles
},
xmltidy: {
all: [].concat( entryFiles, noteFiles, "categories.xml" )
},
"build-xml-entries": {
all: entryFiles
},
"build-resources": {
all: grunt.file.expandFiles( "resources/*" )
},
wordpress: grunt.utils._.extend({
dir: "dist/wordpress"
}, grunt.file.readJSON( "config.json" ) )
});
grunt.registerTask( "build-pages", function() {
var task = this,
taskDone = task.async(),
targetDir = grunt.config( "wordpress.dir" ) + "/posts/page/";
grunt.file.mkdir( targetDir );
grunt.utils.async.forEachSeries( pageFiles, function( fileName, fileDone ) {
var targetFileName = targetDir + path.basename( fileName );
grunt.verbose.write( "Reading " + fileName + "..." );
grunt.verbose.ok();
grunt.verbose.write( "Pygmentizing " + targetFileName + "..." );
pygmentize.file( fileName, function( error, data ) {
if ( error ) {
grunt.verbose.error();
grunt.log.error( error );
fileDone();
return;
}
grunt.verbose.ok();
grunt.file.write( targetFileName, data );
fileDone();
});
}, function() {
if ( task.errorCount ) {
grunt.warn( "Task \"" + task.name + "\" failed." );
taskDone();
return;
}
grunt.log.writeln( "Built " + pageFiles.length + " pages." );
taskDone();
});
});
grunt.registerTask( "default", "build-wordpress" );
grunt.registerTask( "build-wordpress", "clean lint xmllint build-pages build-xml-entries build-xml-categories build-resources" );
grunt.registerTask( "tidy", "xmllint xmltidy" );
};