Skip to content

Commit d1068b1

Browse files
committed
feat(pages): use content collection for staticPaths
1 parent ff2264e commit d1068b1

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

src/pages/[locale]/[...path]/index.astro

+7-15
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
---
2-
import { datocmsCollection, datocmsRequest } from '@lib/datocms';
2+
import { getCollection } from '@lib/collections';
3+
import { datocmsRequest } from '@lib/datocms';
34
import { getPageHref } from '@lib/routing/';
45
import {
56
getPagePath,
67
getPageSlugFromPath,
78
getParentPages,
89
} from '@lib/routing/page';
910
import {
10-
PageRoute as fragment,
11-
type PageQuery,
12-
type PageRouteFragment,
11+
type PageQuery,
1312
type SiteLocale
1413
} from '@lib/datocms/types';
1514
import type { PageUrl } from '@lib/seo';
@@ -21,17 +20,10 @@ import PreviewModeSubscription from '@components/PreviewMode/PreviewModeSubscrip
2120
import query from './_index.query.graphql';
2221
2322
export async function getStaticPaths() {
24-
const pages = await datocmsCollection<PageRouteFragment>({
25-
collection: 'Pages',
26-
fragment,
27-
});
28-
return pages.flatMap((page) => {
29-
const locales = page._allSlugLocales
30-
?.map((slug) => slug.locale)
31-
.filter((locale) => !!locale);
32-
return locales?.map((locale) => {
33-
return { params: { locale, path: getPagePath({ page, locale }) } };
34-
});
23+
const pages = await getCollection('Pages');
24+
return pages.map(({ data: page }) => {
25+
const { locale } = page;
26+
return { params: { locale, path: getPagePath({ page, locale }) } };
3527
});
3628
}
3729

0 commit comments

Comments
 (0)