From 76ba5d043eefb52fa6c08a766f1076df283377f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Wed, 28 Feb 2024 10:26:04 +0100 Subject: [PATCH] Use customization.title instead of space.title (#194) * Use customization.title instead of space.title * Format * Fix TS --- .../(space)/(content)/[[...pathname]]/page.tsx | 6 ++++-- src/app/(space)/(content)/layout.tsx | 2 +- .../(core)/~gitbook/ogimage/[pageId]/route.tsx | 6 ++++-- src/app/(space)/(core)/~gitbook/pdf/page.tsx | 18 +++++++++++++----- src/components/Header/HeaderLogo.tsx | 2 +- 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/app/(space)/(content)/[[...pathname]]/page.tsx b/src/app/(space)/(content)/[[...pathname]]/page.tsx index e5e7d5174..5bf63e595 100644 --- a/src/app/(space)/(content)/[[...pathname]]/page.tsx +++ b/src/app/(space)/(content)/[[...pathname]]/page.tsx @@ -90,13 +90,15 @@ export async function generateViewport({ params }: { params: PagePathParams }): } export async function generateMetadata({ params }: { params: PagePathParams }): Promise { - const { space, page, customization } = await fetchPageData(params); + const { space, page, customization, collection } = await fetchPageData(params); if (!page) { notFound(); } return { - title: `${page.title} | ${space.title}`, + title: [page.title, customization.title ?? space.title, collection?.title] + .filter(Boolean) + .join(' | '), description: page.description ?? '', openGraph: { images: [ diff --git a/src/app/(space)/(content)/layout.tsx b/src/app/(space)/(content)/layout.tsx index 02be43a1a..b12d8f98b 100644 --- a/src/app/(space)/(content)/layout.tsx +++ b/src/app/(space)/(content)/layout.tsx @@ -91,7 +91,7 @@ export async function generateMetadata(): Promise { const customIcon = 'icon' in customization.favicon ? customization.favicon.icon : null; return { - title: `${space.title}`, + title: `${collection ? collection.title : customization.title ?? space.title}`, generator: `GitBook (${buildVersion()})`, // We pass `metadataBase` to avoid warnings from Next, but we still use absolute URLs // as metadataBase doesn't seem to work well on next-on-cloudflare. diff --git a/src/app/(space)/(core)/~gitbook/ogimage/[pageId]/route.tsx b/src/app/(space)/(core)/~gitbook/ogimage/[pageId]/route.tsx index f77489c39..7d55db338 100644 --- a/src/app/(space)/(core)/~gitbook/ogimage/[pageId]/route.tsx +++ b/src/app/(space)/(core)/~gitbook/ogimage/[pageId]/route.tsx @@ -11,7 +11,7 @@ export const runtime = 'edge'; * Render the OpenGraph image for a space. */ export async function GET(req: NextRequest, { params }: { params: PageIdParams }) { - const { space, page, customization } = await fetchPageData(params); + const { space, page, customization, collection } = await fetchPageData(params); const url = new URL(space.urls.published ?? space.urls.app); if (customization.socialPreview.url) { @@ -30,7 +30,9 @@ export async function GET(req: NextRequest, { params }: { params: PageIdParams } flexDirection: 'column', }} > -

{space.title}

+

+ {collection?.title ?? customization.title ?? space.title} +

{page ? page.title : 'Not found'}

diff --git a/src/app/(space)/(core)/~gitbook/pdf/page.tsx b/src/app/(space)/(core)/~gitbook/pdf/page.tsx index cb3747410..d38e36f25 100644 --- a/src/app/(space)/(core)/~gitbook/pdf/page.tsx +++ b/src/app/(space)/(core)/~gitbook/pdf/page.tsx @@ -1,5 +1,11 @@ import { ArrowLeft, Printer } from '@geist-ui/icons'; -import { Revision, RevisionPageDocument, RevisionPageGroup, Space } from '@gitbook/api'; +import { + CustomizationSettings, + Revision, + RevisionPageDocument, + RevisionPageGroup, + Space, +} from '@gitbook/api'; import { Metadata } from 'next'; import { notFound } from 'next/navigation'; import * as React from 'react'; @@ -135,7 +141,7 @@ export default async function PDFHTMLOutput(props: { searchParams: { [key: strin } /> - {pdfParams.only ? null : } + {pdfParams.only ? null : } {pages.map(({ page, depth }) => page.type === 'group' ? ( @@ -166,13 +172,15 @@ export default async function PDFHTMLOutput(props: { searchParams: { [key: strin ); } -async function PDFSpaceIntro(props: { space: Space }) { - const { space } = props; +async function PDFSpaceIntro(props: { space: Space; customization: CustomizationSettings }) { + const { space, customization } = props; return (
-

{space.title}

+

+ {customization.title ?? space.title} +

); diff --git a/src/components/Header/HeaderLogo.tsx b/src/components/Header/HeaderLogo.tsx index 62fedd361..09f5d35da 100644 --- a/src/components/Header/HeaderLogo.tsx +++ b/src/components/Header/HeaderLogo.tsx @@ -135,7 +135,7 @@ function LogoFallback(props: HeaderLogoProps) { : 'text-header-link', )} > - {collection ? collection.title : space.title} + {collection ? collection.title : customization.title ?? space.title} );