forked from jquery/learn.jquery.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
60 lines (47 loc) · 1.17 KB
/
Gruntfile.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
var spawnback = require( "spawnback" ),
jqueryContent = require( "grunt-jquery-content" );
module.exports = function( grunt ) {
grunt.loadNpmTasks( "grunt-jquery-content" );
grunt.initConfig({
"build-posts": {
page: "page/**"
},
"build-resources": {
all: "resources/**"
},
wordpress: (function() {
var config = require( "./config" );
config.dir = "dist/wordpress";
return config;
})()
});
function getOrderMap() {
var map = {},
index = 0;
function walk( items, prefix ) {
items.forEach(function( item ) {
if ( typeof item === "object" ) {
var page = Object.keys( item )[ 0 ];
map[ prefix + page ] = ++index;
walk( item[ page ], prefix + page + "/" );
} else {
map[ prefix + item ] = ++index;
}
});
}
walk( require( "./order" ), "" );
return map;
}
jqueryContent.postPreprocessors.page = (function() {
var orderMap = getOrderMap();
return function( post, postPath, callback ) {
var slug = postPath.replace( /^.+?\/(.+)\.\w+$/, "$1" ),
menuOrder = orderMap[ slug ];
if ( menuOrder ) {
post.menuOrder = menuOrder;
}
callback( null, post );
};
})();
grunt.registerTask( "build", [ "build-posts", "build-resources" ] );
};