|
| 1 | +import type { Metadata } from 'next'; |
| 2 | + |
| 3 | +export const APP_TITLE = 'Volvox.Bot - AI Powered Discord Bot'; |
| 4 | + |
| 5 | +interface DashboardTitleMatcher { |
| 6 | + matches: (pathname: string) => boolean; |
| 7 | + title: string; |
| 8 | +} |
| 9 | + |
| 10 | +const dashboardTitleMatchers: DashboardTitleMatcher[] = [ |
| 11 | + { |
| 12 | + matches: (pathname) => pathname.startsWith('/dashboard/members/'), |
| 13 | + title: 'Member Details', |
| 14 | + }, |
| 15 | + { |
| 16 | + matches: (pathname) => pathname.startsWith('/dashboard/conversations/'), |
| 17 | + title: 'Conversation Details', |
| 18 | + }, |
| 19 | + { |
| 20 | + matches: (pathname) => pathname.startsWith('/dashboard/tickets/'), |
| 21 | + title: 'Ticket Details', |
| 22 | + }, |
| 23 | + { |
| 24 | + matches: (pathname) => pathname === '/dashboard', |
| 25 | + title: 'Overview', |
| 26 | + }, |
| 27 | + { |
| 28 | + matches: (pathname) => pathname.startsWith('/dashboard/moderation'), |
| 29 | + title: 'Moderation', |
| 30 | + }, |
| 31 | + { |
| 32 | + matches: (pathname) => pathname.startsWith('/dashboard/temp-roles'), |
| 33 | + title: 'Temp Roles', |
| 34 | + }, |
| 35 | + { |
| 36 | + matches: (pathname) => pathname.startsWith('/dashboard/ai'), |
| 37 | + title: 'AI Chat', |
| 38 | + }, |
| 39 | + { |
| 40 | + matches: (pathname) => pathname.startsWith('/dashboard/members'), |
| 41 | + title: 'Members', |
| 42 | + }, |
| 43 | + { |
| 44 | + matches: (pathname) => pathname.startsWith('/dashboard/conversations'), |
| 45 | + title: 'Conversations', |
| 46 | + }, |
| 47 | + { |
| 48 | + matches: (pathname) => pathname.startsWith('/dashboard/tickets'), |
| 49 | + title: 'Tickets', |
| 50 | + }, |
| 51 | + { |
| 52 | + matches: (pathname) => pathname.startsWith('/dashboard/config'), |
| 53 | + title: 'Bot Config', |
| 54 | + }, |
| 55 | + { |
| 56 | + matches: (pathname) => pathname.startsWith('/dashboard/audit-log'), |
| 57 | + title: 'Audit Log', |
| 58 | + }, |
| 59 | + { |
| 60 | + matches: (pathname) => pathname.startsWith('/dashboard/performance'), |
| 61 | + title: 'Performance', |
| 62 | + }, |
| 63 | + { |
| 64 | + matches: (pathname) => pathname.startsWith('/dashboard/logs'), |
| 65 | + title: 'Logs', |
| 66 | + }, |
| 67 | + { |
| 68 | + matches: (pathname) => pathname.startsWith('/dashboard/settings'), |
| 69 | + title: 'Settings', |
| 70 | + }, |
| 71 | +]; |
| 72 | + |
| 73 | +function normalizePathname(pathname: string | null | undefined): string | null { |
| 74 | + if (!pathname) { |
| 75 | + return null; |
| 76 | + } |
| 77 | + |
| 78 | + const trimmedPathname = |
| 79 | + pathname.endsWith('/') && pathname !== '/' ? pathname.slice(0, -1) : pathname; |
| 80 | + return trimmedPathname || '/'; |
| 81 | +} |
| 82 | + |
| 83 | +export function formatDocumentTitle(pageTitle?: string | null): string { |
| 84 | + return pageTitle ? `${pageTitle} - ${APP_TITLE}` : APP_TITLE; |
| 85 | +} |
| 86 | + |
| 87 | +export function getDashboardPageTitle(pathname: string | null | undefined): string | null { |
| 88 | + const normalizedPathname = normalizePathname(pathname); |
| 89 | + if (!normalizedPathname) { |
| 90 | + return null; |
| 91 | + } |
| 92 | + |
| 93 | + const matchedRoute = dashboardTitleMatchers.find(({ matches }) => matches(normalizedPathname)); |
| 94 | + return matchedRoute?.title ?? null; |
| 95 | +} |
| 96 | + |
| 97 | +export function getDashboardDocumentTitle(pathname: string | null | undefined): string { |
| 98 | + return formatDocumentTitle(getDashboardPageTitle(pathname)); |
| 99 | +} |
| 100 | + |
| 101 | +export function createPageMetadata(title: string, description?: string): Metadata { |
| 102 | + if (!description) { |
| 103 | + return { title }; |
| 104 | + } |
| 105 | + |
| 106 | + return { |
| 107 | + title, |
| 108 | + description, |
| 109 | + }; |
| 110 | +} |
0 commit comments