🐛 fix(metadata): Global metadata

This commit is contained in:
web@ppanel 2024-11-15 22:37:49 +07:00
parent 74cb16b1ae
commit 15d5ecfc80
2 changed files with 50 additions and 38 deletions

View File

@ -13,25 +13,31 @@ import NextTopLoader from 'nextjs-toploader';
import React from 'react'; import React from 'react';
export async function generateMetadata(): Promise<Metadata> { export async function generateMetadata(): Promise<Metadata> {
const config = await getGlobalConfig({ skipErrorHandler: true }).then((res) => res.data.data!); try {
const site = config.site || {}; const config = await getGlobalConfig({ skipErrorHandler: true }).then((res) => res.data.data!);
return { const site = config.site || {};
title: { return {
default: `${site.site_name}`, title: {
template: `%s | ${site.site_name}`, default: `${site.site_name}`,
}, template: `%s | ${site.site_name}`,
description: site.site_desc, },
icons: { description: site.site_desc,
icon: site.site_logo icons: {
? [ icon: site.site_logo
{ ? [
url: site.site_logo, {
sizes: 'any', url: site.site_logo,
}, sizes: 'any',
] },
: [], ]
}, : [],
}; },
};
} catch (error) {
return {
title: { default: 'PPanel', template: '%s | PPanel' },
};
}
} }
export default async function RootLayout({ children }: { children: React.ReactNode }) { export default async function RootLayout({ children }: { children: React.ReactNode }) {

View File

@ -13,25 +13,31 @@ import NextTopLoader from 'nextjs-toploader';
import React from 'react'; import React from 'react';
export async function generateMetadata(): Promise<Metadata> { export async function generateMetadata(): Promise<Metadata> {
const config = await getGlobalConfig({ skipErrorHandler: true }).then((res) => res.data.data!); try {
const site = config?.site || {}; const config = await getGlobalConfig({ skipErrorHandler: true }).then((res) => res.data.data!);
return { const site = config.site || {};
title: { return {
default: `${site.site_name}`, title: {
template: `%s | ${site.site_name}`, default: `${site.site_name}`,
}, template: `%s | ${site.site_name}`,
description: site.site_desc, },
icons: { description: site.site_desc,
icon: site.site_logo icons: {
? [ icon: site.site_logo
{ ? [
url: site.site_logo, {
sizes: 'any', url: site.site_logo,
}, sizes: 'any',
] },
: [], ]
}, : [],
}; },
};
} catch (error) {
return {
title: { default: 'PPanel', template: '%s | PPanel' },
};
}
} }
export default async function RootLayout({ children }: { children: React.ReactNode }) { export default async function RootLayout({ children }: { children: React.ReactNode }) {