♻️ refactor(config): GenerateMetadata

This commit is contained in:
web@ppanel 2024-11-16 14:06:34 +07:00
parent 15d5ecfc80
commit a0bb101126
20 changed files with 87 additions and 62 deletions

View File

@ -13,31 +13,45 @@ 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> {
try { let site: API.SiteConfig | undefined;
const config = await getGlobalConfig({ skipErrorHandler: true }).then((res) => res.data.data!);
const site = config.site || {}; await getGlobalConfig({ skipErrorHandler: true })
return { .then((res) => {
title: { const config = res.data.data;
default: `${site.site_name}`, site = config?.site || undefined;
template: `%s | ${site.site_name}`, })
}, .catch((error) => {
description: site.site_desc, console.error('Error fetching global config:', error);
icons: { });
icon: site.site_logo
? [ const defaultMetadata = {
{ title: {
url: site.site_logo, default: site?.site_name || `PPanel`,
sizes: 'any', template: `%s | ${site?.site_name || 'PPanel'}`,
}, },
] description: site?.site_desc || '',
: [], icons: {
}, icon: site?.site_logo
}; ? [
} catch (error) { {
return { url: site.site_logo,
title: { default: 'PPanel', template: '%s | PPanel' }, sizes: 'any',
}; },
} ]
: [
{ url: '/favicon.ico', sizes: '48x48' },
{ url: '/favicon.svg', type: 'image/svg+xml' },
],
apple: site?.site_logo || '/apple-touch-icon.png',
},
manifest: '/site.webmanifest',
themeColor: [
{ media: '(prefers-color-scheme: light)', color: '#FFFFFF' },
{ media: '(prefers-color-scheme: dark)', color: '#000000' },
],
};
return defaultMetadata;
} }
export default async function RootLayout({ children }: { children: React.ReactNode }) { export default async function RootLayout({ children }: { children: React.ReactNode }) {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 985 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 394 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 858 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 67 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 765 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -1,7 +1,6 @@
{ {
"background_color": "#FFFFFF", "name": "PPanel",
"description": "PPanel is a pure, professional, and perfect open-source proxy panel tool, designed to be your ideal choice for learning and practical use.", "short_name": "PPanel",
"display": "standalone",
"icons": [ "icons": [
{ {
"src": "/pwa-192x192.png", "src": "/pwa-192x192.png",
@ -28,8 +27,8 @@
"purpose": "maskable" "purpose": "maskable"
} }
], ],
"name": "PPanel",
"short_name": "PPanel",
"start_url": "/", "start_url": "/",
"display": "standalone",
"background_color": "#FFFFFF",
"theme_color": "#FFFFFF" "theme_color": "#FFFFFF"
} }

View File

@ -13,31 +13,44 @@ 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> {
try { let site: API.SiteConfig | undefined;
const config = await getGlobalConfig({ skipErrorHandler: true }).then((res) => res.data.data!);
const site = config.site || {}; await getGlobalConfig({ skipErrorHandler: true })
return { .then((res) => {
title: { const config = res.data.data;
default: `${site.site_name}`, site = config?.site || undefined;
template: `%s | ${site.site_name}`, })
}, .catch((error) => {
description: site.site_desc, console.error('Error fetching global config:', error);
icons: { });
icon: site.site_logo
? [ const defaultMetadata = {
{ title: {
url: site.site_logo, default: site?.site_name || `PPanel`,
sizes: 'any', template: `%s | ${site?.site_name || 'PPanel'}`,
}, },
] description: site?.site_desc || '',
: [], icons: {
}, icon: site?.site_logo
}; ? [
} catch (error) { {
return { url: site.site_logo,
title: { default: 'PPanel', template: '%s | PPanel' }, sizes: 'any',
}; },
} ]
: [
{ url: '/favicon.ico', sizes: '48x48' },
{ url: '/favicon.svg', type: 'image/svg+xml' },
],
apple: site?.site_logo || '/apple-touch-icon.png',
},
manifest: '/site.webmanifest',
themeColor: [
{ media: '(prefers-color-scheme: light)', color: '#FFFFFF' },
{ media: '(prefers-color-scheme: dark)', color: '#000000' },
],
};
return defaultMetadata;
} }
export default async function RootLayout({ children }: { children: React.ReactNode }) { export default async function RootLayout({ children }: { children: React.ReactNode }) {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 985 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 394 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 858 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 67 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 765 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -1,7 +1,6 @@
{ {
"background_color": "#FFFFFF", "name": "PPanel",
"description": "PPanel is a pure, professional, and perfect open-source proxy panel tool, designed to be your ideal choice for learning and practical use.", "short_name": "PPanel",
"display": "standalone",
"icons": [ "icons": [
{ {
"src": "/pwa-192x192.png", "src": "/pwa-192x192.png",
@ -28,8 +27,8 @@
"purpose": "maskable" "purpose": "maskable"
} }
], ],
"name": "PPanel",
"short_name": "PPanel",
"start_url": "/", "start_url": "/",
"display": "standalone",
"background_color": "#FFFFFF",
"theme_color": "#FFFFFF" "theme_color": "#FFFFFF"
} }