Last active
January 9, 2021 23:31
-
-
Save MaikelVeen/ebb57848c72d43227584857c40cfb088 to your computer and use it in GitHub Desktop.
Getting the paths from the manifest including dynamic routes
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
const GetPathsFromManifest = (manifest: any, basePath: string, host: string): Array<Url> => { | |
let routes: Array<string> = []; | |
for (let [route, file] of Object.entries(manifest)) { | |
if (!isNextInternalUrl(route)) { | |
// Add static paths | |
routes = routes.concat(route); | |
} else if (isDynamicUrl(route)) { | |
// Add dynamic paths | |
const dynamicRoute: DynamicRoute = GetBuildPath(route, basePath); | |
routes = routes.concat(GetDynamicPaths(dynamicRoute)); | |
} | |
} | |
let sitemapUrls: Array<Url> = []; | |
routes.forEach((route) => { | |
sitemapUrls.push({ host: host, route: route }); | |
}); | |
return sitemapUrls; | |
}; | |
type DynamicRoute = { | |
buildPath: string; | |
slug: string; | |
} | |
const isDynamicUrl = (path: string): boolean => { | |
return new RegExp(/.*\[.*\].*/).test(path); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment