Skip to content

Commit 7b9a384

Browse files
committed
Create util for metadata
1 parent 3ada617 commit 7b9a384

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

src/app/not-found.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import { Container, Link, Stack, Typography } from "@mui/material";
2+
import { Metadata } from "next";
23
import NextLink from "next/link";
34

45
import { Toskamopo } from "@/components/Toskamopo";
6+
import { getTitle } from "@/utils/metadata";
7+
8+
export const metadata: Metadata = {
9+
title: getTitle(["404"]),
10+
description: "Sivua ei löytynyt",
11+
};
512

613
const NotFound = () => {
714
return (

src/app/page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ import { Projects } from "@/components/Projects";
99
import { Section } from "@/components/Section";
1010
import { ToskaLogo } from "@/components/ToskaLogo";
1111
import { getProjects } from "@/lib/projects";
12+
import { getTitle } from "@/utils/metadata";
1213

1314
export const metadata: Metadata = {
14-
title: "Toska",
15+
title: getTitle(),
1516
description: "Toskan kotisivut",
1617
};
1718

src/app/projects/[name]/page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { notFound } from "next/navigation";
55

66
import { MarkdownContainer } from "@/components/MarkdownContainer";
77
import { getProjectByName } from "@/lib/projects";
8+
import { getTitle } from "@/utils/metadata";
89

910
type Props = Promise<{ name: string }>;
1011

@@ -19,7 +20,7 @@ export async function generateMetadata({
1920
const projectName = project?.title || "Tuntematon projekti";
2021

2122
return {
22-
title: `${projectName} - Projektit - Toska`,
23+
title: getTitle([projectName, "Projektit"]),
2324
description: `${projectName} on Toskan kehittämä sovellus`,
2425
};
2526
}

src/utils/metadata.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export const getTitle = (titleParts?: string[]) => {
2+
const baseTitle = "Toska";
3+
const separator = " - ";
4+
5+
if (!titleParts || titleParts.length === 0) {
6+
return baseTitle;
7+
}
8+
9+
return `${titleParts.join(separator)}${separator}${baseTitle}`;
10+
};

0 commit comments

Comments
 (0)