Skip to content

Instantly share code, notes, and snippets.

@handerson
Created December 11, 2022 20:16
Show Gist options
  • Save handerson/4c1fd086e6323e47f797eb558c8bf261 to your computer and use it in GitHub Desktop.
Save handerson/4c1fd086e6323e47f797eb558c8bf261 to your computer and use it in GitHub Desktop.
collect all the files known to harp as an array. http://harpjs.com/recipes/print-debugging
<% const flattenPublicJSON = (obj = {}, res = [], extraKey = '/') => {
for(key in obj){
if(Array.isArray(obj[key])){
flattenPublicJSON(obj[key], res, `${extraKey}`);
}else if(key === '_contents'){
res.push(`${extraKey}/${obj[key]}`);
} else if(key === '_data'){
//ignore
} else if(typeof obj[key] !== 'object'){
res.push(`${extraKey}${obj[key]}`);
}else{
flattenPublicJSON(obj[key], res, `${extraKey}${key}/`);
};
};
return res;
};%>
<pre><%- JSON.stringify(flattenPublicJSON(public), null, '\t') %></pre>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment