Skip to content

Commit ae93a9e

Browse files
committed
Upgrade to grunt-jquery-content 0.6.0; re-implement menu order handling.
1 parent 3fb611d commit ae93a9e

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

grunt.js

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
var config = require("./config.json");
1+
var yaml = require( "js-yaml" ),
2+
config = require("./config.json");
23

34
module.exports = function( grunt ) {
45

@@ -41,9 +42,56 @@ grunt.initConfig({
4142
wordpress: grunt.utils._.extend({
4243
dir: "dist/wordpress",
4344
order: "order.yml"
44-
}, grunt.file.readJSON( "config.json" ) )
45+
}, grunt.file.readJSON( "config.json" ) )
4546
});
4647

48+
49+
50+
// Process a YAML order file and return an object of page slugs and their ordinal indices
51+
grunt.registerHelper( "read-order", function( orderFile ) {
52+
var order,
53+
map = {},
54+
index = 0;
55+
56+
try {
57+
order = yaml.load( grunt.file.read( orderFile ) );
58+
} catch( error ) {
59+
grunt.warn( "Invalid order file: " + orderFile );
60+
return null;
61+
}
62+
63+
order.forEach(function(chapter) {
64+
var article, title;
65+
66+
if ( grunt.utils._.isObject( chapter ) ) {
67+
title = Object.keys( chapter )[ 0 ];
68+
map[ title ] = ++index;
69+
70+
chapter[ title ].forEach(function( article ) {
71+
map[ title + "/" + article ] = ++index;
72+
});
73+
} else {
74+
map[ title ] = ++index;
75+
}
76+
});
77+
return map;
78+
});
79+
80+
grunt.registerHelper( "build-pages-preprocess", (function() {
81+
var orderMap = grunt.helper( "read-order", "order.yml" );
82+
83+
return function( content, post ) {
84+
var menuOrder = orderMap[ post.__slug ];
85+
if ( menuOrder ) {
86+
post.menuOrder = menuOrder;
87+
}
88+
89+
return content;
90+
};
91+
})());
92+
93+
94+
4795
grunt.registerTask( "default", "wordpress-deploy" );
4896
grunt.registerTask( "build-wordpress", "check-modules clean lint build-pages build-resources");
4997
grunt.registerTask( "deploy", "wordpress-deploy" );

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"grunt-clean": "0.3.0",
2626
"grunt-html": "0.1.1",
2727
"grunt-wordpress": "1.0.3",
28-
"grunt-jquery-content": "0.5.15",
29-
"grunt-check-modules": "0.1.0"
28+
"grunt-jquery-content": "0.6.0",
29+
"grunt-check-modules": "0.1.0",
30+
"js-yaml": "1.0.2"
3031
}
3132
}

0 commit comments

Comments
 (0)