-
Notifications
You must be signed in to change notification settings - Fork 352
Expand file tree
/
Copy pathlayout.tsx
More file actions
58 lines (50 loc) · 1.94 KB
/
layout.tsx
File metadata and controls
58 lines (50 loc) · 1.94 KB
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
import React from "react";
import { Metadata } from "next";
import { DEFAULT_LANGUAGE_CODE } from "@/features/localization/localization.config";
import { cookies } from "next/headers";
import { PREFERRED_THEME_COOKIE_KEY } from "@/features/themes/theme.config";
import { PageLayoutComponent } from "@/features/common/components/layout/page-layout/page-layout.component";
import { PageMetadataProps } from "@/features/common/models/page-metadata.props";
import { getHomeDictionary } from "@/features/localization/services/language-dictionary.service";
import { generatePageMetadata } from "@/libs/metadata/metadata.service";
import { createUrlPath } from "@/libs/utils/path.utils";
import { siteTree } from "@/features/seo/site-tree";
import { ThemeCookieValues } from "@/features/common/values/theme.values";
import { getSanitizedThemeCookieValue } from "@/features/themes/services/theme.utils";
export async function generateStaticParams() {
return [{ language: "en" }];
}
export async function generateMetadata({
params: { language },
}: PageMetadataProps): Promise<Metadata> {
const dictionary = getHomeDictionary(language);
return generatePageMetadata({
languageCode: language,
metadata: dictionary.metadata,
pagePath: createUrlPath([siteTree.root.urlPath]),
canonical: `/${language}`,
});
}
export default function RootLayout({
children,
params,
}: {
children: React.ReactNode;
params: { language: string };
}) {
const { language: languageCode = DEFAULT_LANGUAGE_CODE } = params;
const preferredThemeCookie = cookies().get(PREFERRED_THEME_COOKIE_KEY);
const sanitizedThemeCookieValue = getSanitizedThemeCookieValue(
preferredThemeCookie?.value || null,
);
const initialThemeCookieValue =
sanitizedThemeCookieValue || ThemeCookieValues.SYSTEM_DARK;
return (
<PageLayoutComponent
languageCode={languageCode}
themeCode={initialThemeCookieValue}
>
{children}
</PageLayoutComponent>
);
}