-
-
Save rayriffy/e031eebe295877e9bfcd750e85454f45 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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