Created
February 11, 2019 02:44
-
-
Save davidroyer/6153b3d07fc63b5cbfc0702ca4fcf057 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import slugify from "slugify"; | |
export const slugifyText = str => | |
slugify(str, { replacement: "-", lower: true, remove: /[$*_+~.()'"!\-:@]/g }); | |
export const uniqueArray = originalArray => [...new Set(originalArray)]; | |
export const getPostsFromTag = (posts, tag) => | |
posts.filter(post => post.tags.map(tag => slugifyText(tag)).includes(tag)); | |
export const tagRoutes = posts => { | |
let tagsArray = []; | |
for (var i = 0; i < posts.length; i++) { | |
for (var n = 0; n < posts[i].tags.length; n++) { | |
tagsArray.push(posts[i].tags[n]); | |
} | |
} | |
return uniqueArray(tagsArray); | |
}; | |
// const allTagsArray = postsArray.map(post => { | |
// if (post.tags && post.tags.length > 0) | |
// return post.tags.map(tag => post.tag) | |
// }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment