From de7f3ec14178232eba71f797ed05dc2392dd1c2a Mon Sep 17 00:00:00 2001 From: StepanovPlaton Date: Sat, 6 Jul 2024 20:18:11 +0400 Subject: [PATCH] Update readme. Add dynamic metatada --- README.md | 4 ++-- src/app/[section]/[item_id]/page.tsx | 17 +++++++++++++++++ src/app/[section]/add/page.tsx | 5 +---- src/app/[section]/page.tsx | 1 - 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ff6ac00..13fa66a 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ ## ToDo - [ ] Dockerfile - [ ] Добавить ссылку на общий репозиторий -- [ ] Теги жанров для сущностей +- [x] Теги жанров для сущностей - [ ] Поиск -- [ ] Динамические метаданные к страницам [section]/* +- [x] Динамические метаданные к страницам [section]/* - [ ] Страница "О проекте" \ No newline at end of file diff --git a/src/app/[section]/[item_id]/page.tsx b/src/app/[section]/[item_id]/page.tsx index ee8ad61..43fd87b 100644 --- a/src/app/[section]/[item_id]/page.tsx +++ b/src/app/[section]/[item_id]/page.tsx @@ -4,6 +4,23 @@ import { ItemCard } from "@/widgets/itemCard"; import { ItemInfo } from "@/widgets/itemInfo"; import { Section } from "@/widgets/section"; import { redirect } from "next/navigation"; +import { Metadata } from "next"; + +export async function generateMetadata({ + params: { section, item_id }, +}: { + params: { section: string; item_id: number }; +}): Promise { + if (!SectionService.isSection(section)) redirect("/"); + const game = await ItemService.itemsConfiguration[ + SectionService.sectionsConfiguration[section].itemType + ].service.Get(item_id); + if (!game) redirect("/"); + return { + title: `.Torrent: ${SectionService.sectionsConfiguration[section].sectionName} - ${game.title}`, + description: `.Torrent: ${SectionService.sectionsConfiguration[section].sectionName} - ${game.description}`, + }; +} export default async function Item({ params: { section, item_id }, diff --git a/src/app/[section]/add/page.tsx b/src/app/[section]/add/page.tsx index d0e72e8..7c1d2c7 100644 --- a/src/app/[section]/add/page.tsx +++ b/src/app/[section]/add/page.tsx @@ -11,10 +11,7 @@ export async function generateMetadata({ }: { params: { section: string }; }): Promise { - if (!SectionService.isSection(section)) { - redirect("/"); - return {}; - } + if (!SectionService.isSection(section)) redirect("/"); return { title: `.Torrent: ${SectionService.sectionsConfiguration[section].addItemText}`, }; diff --git a/src/app/[section]/page.tsx b/src/app/[section]/page.tsx index 825e290..91da2e7 100644 --- a/src/app/[section]/page.tsx +++ b/src/app/[section]/page.tsx @@ -12,7 +12,6 @@ export async function generateMetadata({ }): Promise { if (!SectionService.isSection(section)) { redirect("/"); - return {}; } return { title: `.Torrent: ${SectionService.sectionsConfiguration[section].sectionName}`,