Skip to content

Commit

Permalink
refactor: filtering is now cumulative
Browse files Browse the repository at this point in the history
  • Loading branch information
kkemple committed Jun 22, 2018
1 parent 1788a2f commit 866bd6d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
4 changes: 3 additions & 1 deletion www/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,13 @@ exports.createPages = ({ graphql, actions }) => {
edge => {
const slug = _.get(edge, `node.fields.slug`)
const draft = _.get(edge, `node.frontmatter.draft`)
if (!slug) return
if (!slug) return undefined

if (_.includes(slug, `/blog/`) && !draft) {
return edge
}

return undefined
}
)

Expand Down
17 changes: 10 additions & 7 deletions www/src/views/showcase/filtered-showcase.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ import presets, { colors } from "../../utils/presets"
import URLQuery from "../../components/url-query"

const filterByCategories = (list, categories) => {
let items = list
const items = list.reduce((aggregated, edge) => {
if (edge.node.categories) {
if (edge.node.categories.filter(c => categories.includes(c)).length) {
aggregated.push(edge)
}

items = items.filter(
({ node }) =>
node.categories &&
node.categories.filter(c => categories.includes(c)).length ===
categories.length
)
return aggregated
}

return aggregated
}, [])

return items
}
Expand Down

0 comments on commit 866bd6d

Please sign in to comment.