Skip to content

Instantly share code, notes, and snippets.

@rayriffy rayriffy/index.js Secret
Created May 4, 2019

Embed
What would you like to do?
/**
* 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
You can’t perform that action at this time.