Skip to content

Instantly share code, notes, and snippets.

@rayriffy
Created May 4, 2019 16:42
Show Gist options
  • Save rayriffy/e031eebe295877e9bfcd750e85454f45 to your computer and use it in GitHub Desktop.
Save rayriffy/e031eebe295877e9bfcd750e85454f45 to your computer and use it in GitHub Desktop.
/**
* Filter only tags object with specified types
* @param {object} nodes healthyTags
* @param {string} type Tag type
*/
const tagFilter = (nodes, type) => {
const res = []
_.each(nodes, node => {
_.each(node.data.raw.tags, tag => {
if (tag.type === type) {
if (_.isEmpty(_.filter(res, node => node.id === tag.id))) {
res.push(tag)
}
}
})
})
return res
}
/**
* Create listing pages for each tags
* @param {string} pathPrefix Tag path prefix
* @param {object} nodes Filtered tag object
* @param {string} name Tag name
*/
const createSlugPages = (pathPrefix, name, nodes) => {
_.each(nodes, tag => {
const qualifiedResults = []
_.each(healthyResults, node => {
if (!_.isEmpty(_.filter(node.data.raw.tags, {id: tag.id}))) qualifiedResults.push(node)
})
createPage({
path: `${pathPrefix}/${tag.id}`,
component: path.resolve('./src/templates/listing.js'),
context: {
subtitle: `${name}/${tag.name}`,
raw: qualifiedResults,
tagStack,
},
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment