Skip to content

Commit

Permalink
hotfix: missing language GROQ param
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiazom committed Oct 14, 2024
1 parent 132b471 commit 48b4498
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 71 deletions.
7 changes: 3 additions & 4 deletions src/app/(main)/[lang]/[...path]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,13 @@ function seoDataFromPageData(

export async function generateMetadata({ params }: Props): Promise<Metadata> {
const { perspective } = getDraftModeInfo();

const language = params.lang;
const pageData = await fetchPageDataFromParams({
language: params.lang,
language,
path: params.path,
perspective: perspective ?? "published",
});

return generateMetadataFromSeo(seoDataFromPageData(pageData));
return generateMetadataFromSeo(seoDataFromPageData(pageData), language);
}

const Page404 = (
Expand Down
92 changes: 57 additions & 35 deletions src/app/(main)/[lang]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import localFont from "next/font/local";
import { draftMode } from "next/headers";

import Footer from "src/components/navigation/footer/Footer";
import FooterPreview from "src/components/navigation/footer/FooterPreview";
import { Header } from "src/components/navigation/header/Header";
Expand All @@ -9,6 +12,7 @@ import { CompanyInfo } from "studio/lib/interfaces/companyDetails";
import { LegalDocument } from "studio/lib/interfaces/legalDocuments";
import { Navigation } from "studio/lib/interfaces/navigation";
import { SocialMediaProfiles } from "studio/lib/interfaces/socialMedia";
import LiveVisualEditing from "studio/lib/loaders/AutomaticVisualEditing";
import {
COMPANY_INFO_QUERY,
LEGAL_DOCUMENTS_BY_LANG_QUERY,
Expand All @@ -22,6 +26,13 @@ import { loadStudioQuery } from "studio/lib/store";

import styles from "./layout.module.css";

import "src/styles/global.css";

const fontBrittiSans = localFont({
src: "../../../../public/_assets/britti-sans-variable.woff2",
variable: "--font-britti-sans",
});

const hasValidData = (data: unknown) => data && Object.keys(data).length > 0;

export default async function Layout({
Expand Down Expand Up @@ -72,44 +83,55 @@ export default async function Layout({

if (!hasMenuData) {
return (
<main id="main" tabIndex={-1} className={styles.offsetForStickyHeader}>
{children}
</main>
<html lang={params.lang}>
<body className={fontBrittiSans.variable}>
<main
id="main"
tabIndex={-1}
className={styles.offsetForStickyHeader}
>
{children}
</main>
</body>
</html>
);
}

return (
<>
<SkipToMain />
{hasHeaderData && isDraftMode ? (
<HeaderPreview
initialNav={initialNav}
initialBrandAssets={initialBrandAssets}
/>
) : (
<Header data={initialNav.data} assets={initialBrandAssets.data} />
)}
<main id="main" tabIndex={-1}>
{children}
</main>
{hasFooterData && isDraftMode ? (
<FooterPreview
initialNav={initialNav}
initialCompanyInfo={initialCompanyInfo}
initialBrandAssets={initialBrandAssets}
initialSoMe={initialSoMe}
initialLegal={initialLegal}
language={params.lang}
/>
) : (
<Footer
navigationData={initialNav.data}
legalData={initialLegal.data}
companyInfo={initialCompanyInfo.data}
brandAssets={initialBrandAssets.data}
soMeData={initialSoMe.data}
/>
)}
</>
<html lang={params.lang}>
<body className={fontBrittiSans.variable}>
<SkipToMain />
{hasHeaderData && isDraftMode ? (
<HeaderPreview
initialNav={initialNav}
initialBrandAssets={initialBrandAssets}
/>
) : (
<Header data={initialNav.data} assets={initialBrandAssets.data} />
)}
<main id="main" tabIndex={-1} className={styles.offsetForStickyHeader}>
{children}
</main>
{hasFooterData && isDraftMode ? (
<FooterPreview
initialNav={initialNav}
initialCompanyInfo={initialCompanyInfo}
initialBrandAssets={initialBrandAssets}
initialSoMe={initialSoMe}
initialLegal={initialLegal}
language={params.lang}
/>
) : (
<Footer
navigationData={initialNav.data}
legalData={initialLegal.data}
companyInfo={initialCompanyInfo.data}
brandAssets={initialBrandAssets.data}
soMeData={initialSoMe.data}
/>
)}
{draftMode().isEnabled && <LiveVisualEditing />}
</body>
</html>
);
}
9 changes: 6 additions & 3 deletions src/app/(main)/[lang]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ import { PageBuilder } from "studio/lib/interfaces/pages";
import { LANDING_PAGE_QUERY } from "studio/lib/queries/siteSettings";
import { loadStudioQuery } from "studio/lib/store";

export async function generateMetadata(): Promise<Metadata> {
export async function generateMetadata({ params }: Props): Promise<Metadata> {
const { data: landingPage } = await loadStudioQuery<PageBuilder | null>(
LANDING_PAGE_QUERY,
{
language: params.lang,
},
);
return generateMetadataFromSeo(landingPage?.seo ?? null);
return generateMetadataFromSeo(landingPage?.seo ?? null, params.lang);
}

const navigationManagerLink = {
Expand All @@ -25,7 +28,7 @@ const navigationManagerLink = {
};

type Props = {
params: { lang: string; slug: string };
params: { lang: string };
};

const Home = async ({ params }: Props) => {
Expand Down
31 changes: 2 additions & 29 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,44 +1,17 @@
import { Metadata } from "next";
import localFont from "next/font/local";
import { draftMode } from "next/headers";

import { generateMetadataFromSeo } from "src/utils/seo";
import { LanguageObject } from "studio/lib/interfaces/supportedLanguages";
import LiveVisualEditing from "studio/lib/loaders/AutomaticVisualEditing";
import { DEFAULT_LANGUAGE_QUERY } from "studio/lib/queries/siteSettings";
import { loadStudioQuery } from "studio/lib/store";

import "src/styles/global.css";

const fontBrittiSans = localFont({
src: "../../public/_assets/britti-sans-variable.woff2",
variable: "--font-britti-sans",
});

export async function generateMetadata(): Promise<Metadata> {
// fallback if no page-specific metadata is provided
return generateMetadataFromSeo(null);
}

export default async function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
let siteLang;

try {
const { data } = await loadStudioQuery<LanguageObject>(
DEFAULT_LANGUAGE_QUERY,
);
siteLang = data.id;
} catch (error) {
console.error("Error loading site settings:", error);
siteLang = "en";
}
return (
<html lang={siteLang}>
<body className={fontBrittiSans.variable}>
<html lang={"en"}>
<body>
{children}
{draftMode().isEnabled && <LiveVisualEditing />}
</body>
Expand Down
2 changes: 2 additions & 0 deletions src/utils/seo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ export const OPEN_GRAPH_IMAGE_DIMENSIONS = {

export async function generateMetadataFromSeo(
seo: SeoData | null,
language: string,
): Promise<Metadata> {
const { data: defaultSeo } = await loadStudioQuery<DefaultSeo | null>(
DEFAULT_SEO_QUERY,
{ language },
);
const { data: companyInfo } = await loadStudioQuery<CompanyInfo | null>(
COMPANY_INFO_QUERY,
Expand Down

0 comments on commit 48b4498

Please sign in to comment.