manifest + fav icon + title page

This commit is contained in:
hamid zarghami
2025-12-23 09:45:01 +03:30
parent bee8127450
commit 8135de464d
5 changed files with 195 additions and 16 deletions
+74 -12
View File
@@ -1,33 +1,95 @@
import PreferenceWrapper from '@/components/wrapper/PreferenceWrapper'
import React from 'react'
import type { Metadata, Viewport } from 'next'
import { getRestaurant } from './lib/getRestaurant'
import { notFound } from 'next/navigation'
export const dynamic = 'force-dynamic'
export const revalidate = 0
type LayoutParams = { name: string }
export async function generateMetadata ({
export async function generateMetadata({
params
}: {
params: Promise<LayoutParams>
}): Promise<Metadata> {
const { name } = await params
return {
title: `${name} Dashboard`,
description: `PWA dashboard for ${name}`,
manifest: `/manifests/${name}/manifest.json`
try {
const restaurant = await getRestaurant(name)
const favicon = restaurant.logo || "/icons/web-app-manifest-192x192.png"
const title = restaurant.seoTitle || restaurant.name
const defaultIcon = "/icons/web-app-manifest-192x192.png"
const iconUrl = favicon || defaultIcon
return {
title,
description: restaurant.seoDescription || restaurant.description || `منوی ${restaurant.name}`,
manifest: `/${name}/manifest.webmanifest`,
icons: {
icon: [
{ url: iconUrl },
{ url: iconUrl, sizes: "192x192", type: "image/png" },
{ url: iconUrl, sizes: "512x512", type: "image/png" },
],
shortcut: iconUrl,
apple: iconUrl,
},
}
} catch {
return {
title: `${name} - Dashboard`,
description: `PWA dashboard for ${name}`,
manifest: `/${name}/manifest.webmanifest`,
icons: {
icon: [
{ url: "/icons/web-app-manifest-192x192.png" },
{ url: "/icons/web-app-manifest-192x192.png", sizes: "192x192", type: "image/png" },
{ url: "/icons/web-app-manifest-512x512.png", sizes: "512x512", type: "image/png" },
],
shortcut: "/icons/web-app-manifest-192x192.png",
apple: "/icons/web-app-manifest-192x192.png",
},
}
}
}
export async function generateViewport (): Promise<Viewport> {
return {
themeColor: '#F4F5F9'
export async function generateViewport({
params
}: {
params: Promise<LayoutParams>
}): Promise<Viewport> {
try {
const { name } = await params
const restaurant = await getRestaurant(name)
return {
themeColor: restaurant.menuColor || '#F4F5F9'
}
} catch {
return {
themeColor: '#F4F5F9'
}
}
}
export default function Layout ({
children
export default async function Layout({
children,
params
}: {
children: React.ReactNode
params: Promise<LayoutParams>
}): React.ReactNode {
return <PreferenceWrapper>{children}</PreferenceWrapper>
}): Promise<React.ReactNode> {
try {
const { name } = await params
await getRestaurant(name)
return <PreferenceWrapper>{children}</PreferenceWrapper>
} catch (error) {
if (error instanceof Error && error.message === 'RESTAURANT_NOT_FOUND') {
notFound()
}
throw error
}
}