import { ROUTES } from '@lumina/market/app/navigation'; import { channelMetadata, getChannel, getRequestTime, readOnServer, } from '@lumina/market/server'; import { toChannelUsername } from '@lumina/market/shared/utils'; import type { Metadata } from 'next'; import { notFound, permanentRedirect } from 'next/navigation'; import { displayUrl } from '../../../../configs'; import { i18n } from '../../../../i18n'; import { ChannelTemplate } from './templates/channel-template'; type ChannelPageProps = { params: Promise<{ username: string }> }; export async function generateMetadata({ params, }: ChannelPageProps): Promise { const username = toChannelUsername((await params).username); if (!username) return { robots: { index: false } }; const channel = await readOnServer(() => getChannel(username)); if (channel.status !== 'ok') return { robots: { index: false } }; if (channel.data.suspended) { return { title: i18n.t('channel:meta.unavailable-title'), robots: { index: false }, }; } return channelMetadata({ channel: channel.data, title: i18n.t('channel:meta.title', { username }), description: i18n.t('channel:meta.description', { username }), }); } /** * A creator's channel, `/@username`. The same server render for every visitor: the header, the * track record and the first posts; subscribe, follow and the locked posts' gates load in the * browser. Any other spelling of the username redirects to the one the API stores. */ export default async function ChannelPage({ params }: ChannelPageProps) { const segment = (await params).username; const username = toChannelUsername(segment); if (!username) notFound(); if (username !== segment) permanentRedirect(ROUTES.channel(username)); const channel = await readOnServer(() => getChannel(username)); if (channel.status !== 'ok') notFound(); return ( ); }