Skip to content

Instantly share code, notes, and snippets.

@dmachat
Created February 12, 2018 18:46
Show Gist options
  • Save dmachat/1e712ff1c3e0cd15ca7014c80dd9e885 to your computer and use it in GitHub Desktop.
Save dmachat/1e712ff1c3e0cd15ca7014c80dd9e885 to your computer and use it in GitHub Desktop.
segment data by timeframe
const timeframes = [
{
name: '1900-1920',
range: [timestamp, timestamp] // you could also parse this from the name
slug: 'timeframes/1900-1920',
},
...
];
function filterDataByTimeframe(range, data) {
return data.filter(item => {
// logic to determine whether item is within range
});
}
timeframes.forEach(timeframe => {
const filteredData = filterDataByTimeframe(timeframe.range, results.data.allMarkdownRemark.edges);
createPaginatedPages({
pathPrefix: timeframe.slug,
edges: filteredData,
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment