Skip to content

Instantly share code, notes, and snippets.

@MaikelVeen
Last active January 9, 2021 23:31
Show Gist options
  • Save MaikelVeen/ebb57848c72d43227584857c40cfb088 to your computer and use it in GitHub Desktop.
Save MaikelVeen/ebb57848c72d43227584857c40cfb088 to your computer and use it in GitHub Desktop.
Getting the paths from the manifest including dynamic routes
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