-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.tsx
61 lines (56 loc) · 1.74 KB
/
index.tsx
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { QueryEngine } from '@snapwp/query';
import { GlobalHead } from './global-head';
import { getIcons } from './icons-metadata';
import type { Metadata } from 'next';
import type { PropsWithChildren, ReactNode } from 'react';
export type RootLayoutProps = {
getGlobalStyles?: ( typeof QueryEngine )[ 'getGlobalStyles' ];
};
/**
* The RootLayout to be used in a NextJS app.
* @param props - The props for the renderer.
* @param props.getGlobalStyles - A async callback to get global styles.
* @param props.children - Child components.
*
* @return The rendered template.
*/
export async function RootLayout( {
getGlobalStyles = QueryEngine.getGlobalStyles,
children,
}: PropsWithChildren< RootLayoutProps > ): Promise< ReactNode > {
const globalHeadProps = await getGlobalStyles();
return (
<html lang="en">
<head>
<GlobalHead { ...globalHeadProps } />
</head>
{ /* suppressHydrationWarning is added to suppress warnings when classes for body are updated on the client */ }
<body suppressHydrationWarning>{ children }</body>
</html>
);
}
/**
* Generate and return root metadata, including icons and other metadata.
*
* @return Merged metadata.
*/
export async function generateRootMetaData(): Promise< Metadata > {
/**
* Fetch icons in required format, apply faviconIcons and apple touch icons in icons metadata property while apply msapplication-TileImage in other metadata property.
*
* @todo Review composability when implementing SEO metadata
*/
const { faviconIcons, appleIcons, msApplicationTileIcon } =
await getIcons();
return {
icons: {
icon: faviconIcons,
apple: appleIcons,
},
other: {
...( msApplicationTileIcon && {
'msapplication-TileImage': msApplicationTileIcon.sourceUrl,
} ),
},
};
}