Skip to content

Commit 21703a3

Browse files
committed
Manifest: Generate categories.json manifest
- Get categories metadata and extend it with its posts by using wordpress-walk-posts
1 parent 271797e commit 21703a3

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

grunt.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,35 @@ grunt.initConfig({
3838
}, grunt.file.readJSON( "config.json" ) )
3939
});
4040

41+
grunt.registerTask( "manifest", "Generate categories.json manifest file", function() {
42+
var categories,
43+
categoryPosts = {},
44+
done = this.async();
45+
46+
categories = require( "./" + grunt.config( "wordpress.dir" ) + "/taxonomies" ).category;
47+
categories.forEach(function( category ) {
48+
category.posts = categoryPosts[ category.slug ] = [];
49+
});
50+
51+
grunt.helper( "wordpress-walk-posts", grunt.config( "wordpress.dir" ), function( post, callback ) {
52+
if ( post.termSlugs && post.termSlugs.category ) {
53+
post.termSlugs.category.forEach(function( slug ) {
54+
categoryPosts[ slug ].push( post );
55+
});
56+
}
57+
callback();
58+
}, function( error ) {
59+
if ( error ) {
60+
grunt.error.log( error.message );
61+
return done( false );
62+
}
63+
64+
grunt.file.write( grunt.config( "wordpress.dir" ) + "/categories.json",
65+
JSON.stringify( categories, null, "\t" ) + "\n" );
66+
done();
67+
});
68+
});
69+
4170
grunt.registerTask( "default", "build-wordpress" );
4271
grunt.registerTask( "build", "build-pages build-xml-entries build-xml-categories build-resources build-xml-full" );
4372
grunt.registerTask( "build-wordpress", "check-modules clean lint xmllint build" );

0 commit comments

Comments
 (0)