Skip to content

Commit fb73555

Browse files
committed
consolidate layout
1 parent 4188487 commit fb73555

File tree

5 files changed

+109
-121
lines changed

5 files changed

+109
-121
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"version":"1.3.0","languages":{"de":{"hash":"de_45ee8a9b41","wasm":"de","page_count":38},"en":{"hash":"en_40a079c681","wasm":"en","page_count":24}}}
1+
{"version":"1.3.0","languages":{"en":{"hash":"en_40e32e4269","wasm":"en","page_count":24},"de":{"hash":"de_8f702a5caf","wasm":"de","page_count":38}}}

src/app/[lang]/layout.tsx

Lines changed: 0 additions & 96 deletions
This file was deleted.

src/app/[lang]/not-found.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { NotFoundPage as default } from "nextra-theme-docs";

src/app/layout.tsx

Lines changed: 93 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,96 @@
1-
// app/layout.tsx
1+
import type { Metadata } from "next";
2+
import { Footer, Layout, Navbar } from "nextra-theme-docs";
3+
import { Banner, Head } from "nextra/components";
4+
import { getPageMap } from "nextra/page-map";
5+
import "nextra-theme-docs/style.css";
6+
import "./styles.css";
7+
import { PageMapItem, Folder, MdxFile } from "nextra";
8+
import { getDictionary } from "@/dictionaries/get-dictionary";
9+
import Image from "next/image";
210

3-
"use client"; // Enables client-side rendering for components that use hooks
4-
import "./styles.css"; // Import global CSS
11+
export async function generateStaticParams() {
12+
return [{ lang: "en" }, { lang: "de" }];
13+
}
14+
15+
export const metadata: Metadata = {
16+
description: "DIY PID Controller für deine Espressomaschine",
17+
title: {
18+
absolute: "",
19+
template: "%s | CC"
20+
},
21+
other: {
22+
"msapplication-TileColor": "#fff"
23+
}
24+
};
25+
26+
function isFolder(item: PageMapItem): item is Folder {
27+
return (item as Folder).children !== undefined;
28+
}
29+
30+
function hasRoute(item: PageMapItem): item is Folder | MdxFile {
31+
return "route" in item;
32+
}
33+
34+
function localizeRoute(item: PageMapItem, lang: string): PageMapItem {
35+
const result = { ...item };
36+
if (hasRoute(result)) {
37+
result.route = result.route.replace("/", `/${lang}/`);
38+
}
39+
if (isFolder(result)) {
40+
result.children = result.children.map((child) => localizeRoute(child, lang));
41+
}
42+
return result;
43+
}
44+
45+
export default async function RootLayout({
46+
children,
47+
params
48+
}: {
49+
children: React.ReactNode;
50+
params: Promise<{ lang?: string }>;
51+
}) {
52+
const lang = (await params).lang ?? "de";
53+
let pageMap = await getPageMap(`/${lang}`);
54+
const dictionary = await getDictionary(lang);
55+
56+
// Localize routes (TODO: This should be done in the page-map module by nextra)
57+
pageMap = [...pageMap.map((page: PageMapItem) => localizeRoute(page, lang))];
558

6-
export default function RootLayout({ children }: { children: React.ReactNode }) {
7-
return <>{children}</>;
59+
const navbar = (
60+
<Navbar
61+
logo={
62+
<>
63+
<Image height={48} width={48} src="/logo.png" alt="CleverCoffee Logo" />
64+
<span className="ms-2 font-extrabold select-none max-md:hidden" title={`${dictionary.logo.title}`}>
65+
<b>{dictionary.logo.title}</b> <span style={{ opacity: "60%" }}>{dictionary.logo.claim}</span>
66+
</span>
67+
</>
68+
}
69+
projectLink="https://github.com/rancilio-pid/clevercoffee"
70+
// Clevercoffee discord server
71+
chatLink="https://discord.com/invite/Kq5RFznuU4"
72+
/>
73+
);
74+
return (
75+
<html lang={lang} dir="ltr" suppressHydrationWarning>
76+
<Head faviconGlyph="✦" />
77+
<body>
78+
<Layout
79+
banner={<Banner storageKey="Clevercoffee 4">CleverCoffee 4</Banner>}
80+
navbar={navbar}
81+
footer={<Footer />}
82+
editLink="Edit this page on GitHub"
83+
docsRepositoryBase="https://github.com/cellcortex"
84+
sidebar={{ defaultMenuCollapseLevel: 1 }}
85+
pageMap={pageMap}
86+
i18n={[
87+
{ locale: "de", name: "Deutsch" },
88+
{ locale: "en", name: "English" }
89+
]}
90+
>
91+
{children}
92+
</Layout>
93+
</body>
94+
</html>
95+
);
896
}

src/app/page.tsx

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,24 @@ const RootRedirect = () => {
2626
}, [router]);
2727

2828
return (
29-
<html lang="en">
30-
<head>
29+
<>
30+
<Head>
3131
<title>CleverCoffee Documentation</title>
3232
<meta name="description" content="CleverCoffee Documentation" />
3333
<title>CleverCoffee</title>
3434
<meta httpEquiv="Content-Language" content="en" />
35-
<link rel="alternate" hrefLang="en" href="https://yourdomain.com/en" />
36-
<link rel="alternate" hrefLang="de" href="https://yourdomain.com/de" />
37-
<link rel="alternate" hrefLang="x-default" href="https://yourdomain.com/en" />
38-
</head>
39-
<body>
40-
<div
41-
style={{
42-
display: "flex",
43-
justifyContent: "center",
44-
alignItems: "center",
45-
height: "100vh"
46-
}}
47-
>
48-
<p>Redirecting to your preferred language...</p>
49-
</div>
50-
</body>
51-
</html>
35+
</Head>
36+
<div
37+
style={{
38+
display: "flex",
39+
justifyContent: "center",
40+
alignItems: "center",
41+
height: "100vh"
42+
}}
43+
>
44+
<p>Redirecting to your preferred language...</p>
45+
</div>
46+
</>
5247
);
5348
};
5449

0 commit comments

Comments
 (0)