-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.astro
33 lines (30 loc) · 1.1 KB
/
index.astro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
---
import { datocmsRequest } from '@lib/datocms';
import type { HomePageQuery, HomePageRecord } from '@lib/datocms/types';
import type { PageUrl } from '@lib/seo';
import { locales } from '@lib/i18n';
import { getHomeHref } from '@lib/routing';
import Layout from '@layouts/Default.astro';
import Blocks from '@blocks/Blocks.astro';
import type { AnyBlock } from '@blocks/Blocks';
import PreviewModeSubscription from '@components/PreviewMode/PreviewModeSubscription.astro';
import query from './_index.query.graphql';
export async function getStaticPaths() {
return locales.map((locale) => ({ params: { locale } }));
}
const { locale } = Astro.params;
const variables = { locale };
const { page } = (await datocmsRequest<HomePageQuery>({
query,
variables,
})) as { page: HomePageRecord };
const pageUrls = locales.map((locale) => ({
locale,
pathname: getHomeHref({ locale }),
})) as PageUrl[];
---
<Layout pageUrls={pageUrls} seoMetaTags={page._seoMetaTags}>
<PreviewModeSubscription query={query} variables={variables} />
<h1>{page.title}</h1>
<Blocks blocks={page.bodyBlocks as AnyBlock[]} />
</Layout>