I'm trying to loop through my Content Tree and pull out metadata from various markdown files. I saw the Paginator plugin example, but I feel like my use case is much more simple than needed from the Paginator.
If my contents dir structure looks like this:
projects/
project-name-1/
index.md
project-name-2/
index.md
project-name-3/
index.md
I want to loop through my contents and retrieve all of the "title" metadata properties. If I try a simple loop in jade, such as:
each project in content.projects
- console.log(project.metadata.title);
I log undefined.
I tried moving this kind of logic into a simple plugin as inspired by the Paginator (written in js):
module.exports = function(env, callback){
_ = require('underscore');
var options = {projects: 'projects'};
function getProjects(contents) {
//helper that returns a list of projects found in *contents*
//note that each article is assumed to have its own directory in the articles directory
// console.dir(contents[options.projects]);
_.each(contents[options.projects], function(i){console.log(i);});
var projects = {};//@todo create a new collection containing each metadata object
return projects;
}
//add the article helper to the environment so we can use it later
env.helpers.getProjects = getProjects;
//tell the plugin manager we are done
callback();
};
and while I'm able to see my metadata inside the logged object, I'm not entirely sure how to access it from here. Is there a simpler way to pull out metadata from the content tree like this? Any help is much appreciated!