Skip to content

Instantly share code, notes, and snippets.

@cfjedimaster
Created August 27, 2015 18:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cfjedimaster/47fd99449959b30ca2d4 to your computer and use it in GitHub Desktop.
Save cfjedimaster/47fd99449959b30ca2d4 to your computer and use it in GitHub Desktop.
POC for generating dynamic paths for HarpJS
/*
The name of the file could be app.js, which could be a requirement. Maybe there could be multiple things it does besides just virtual paths and stuff.
*/
//public is a copy of the Harp global data, basically everything you normally get access to
function generatePaths(public) {
//result must be an array
var result = [];
//lets make categories, pretend public.categories is an array of labels
for(var i=0; i<public.categories.length; i++) {
var newPage = {};
//path is required. can be html, xml, etc
newPage.path = "/categories/"+public.categories[i]+".html";
//body is required
//maybe if this is run via Node we can do a filesync read?
newPage.body = "<p>This is for category "+public.categories[i]+"</p>";
result.push(newPage);
}
//lets make some random other page
var someOther = {path:"/virtual/something.html", body:"<h1>Hello World</h1>"};
result.push(someOther);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment