Last active
June 28, 2021 20:36
-
-
Save DoctorDerek/71d9f6ecdaea6657474e51383c890944 to your computer and use it in GitHub Desktop.
Real world use case for .filter(Boolean) by @DoctorDerek https://medium.com/p/87b5112f9f6d
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
export async function getStaticPaths() { | |
// search 1 level recursively in @/data/ | |
const dataRegExpMarkdown = /(.+)?\\(.+)?\\(.+)?\.md/ | |
// ["data\\hosting\\packages.md", "data", "hosting", "packages"] | |
const paths: any[] = getFilesRecursively("data") | |
.map((path: string) => dataRegExpMarkdown.exec(path)) | |
.filter((item: any[]) => Boolean(item)) // remove falsy | |
.map((item: any[]) => ({ | |
params: { | |
path: item[2], // "hosting" (supports 1 directory) | |
slug: item[3], // "packages" (excluding .md or .mdx) | |
}, | |
})) | |
return { | |
paths: paths, | |
fallback: false, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment