Skip to content

Commit

Permalink
⚑ perf: Use nextjs pwa feat to gen manifest file (#4042)
Browse files Browse the repository at this point in the history
* ⚑ perf: Use nextjs pwa feat to gen manifest file

* πŸ› fix: Fix review problem

* βœ… test: Add test

* πŸ’„ style: Update next config

* πŸ› fix: Fix test config

* πŸ’„ style: Update layout
  • Loading branch information
canisminor1990 authored Sep 21, 2024
1 parent d3aa60a commit 8afb4e2
Show file tree
Hide file tree
Showing 15 changed files with 729 additions and 176 deletions.
47 changes: 46 additions & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,19 @@ const nextConfig = {
],
source: '/apple-touch-icon.png',
},
{
headers: [
{
key: 'Content-Type',
value: 'application/javascript; charset=utf-8',
},
{
key: 'Content-Security-Policy',
value: "default-src 'self'; script-src 'self'",
},
],
source: '/sw.js',
},
];
},

Expand All @@ -113,10 +126,42 @@ const nextConfig = {
source: '/sitemap.xml',
},
{
destination: '/discover',
destination: '/manifest.webmanifest',
permanent: true,
source: '/manifest.json',
},
{
destination: '/discover/assistant/:slug',
has: [
{
key: 'agent',
type: 'query',
value: '(?<slug>.*)',
},
],
permanent: true,
source: '/market',
},
{
destination: '/discover/assistants',
permanent: true,
source: '/discover/assistant',
},
{
destination: '/discover/models',
permanent: true,
source: '/discover/model',
},
{
destination: '/discover/plugins',
permanent: true,
source: '/discover/plugin',
},
{
destination: '/discover/providers',
permanent: true,
source: '/discover/provider',
},
{
destination: '/settings/common',
permanent: true,
Expand Down
166 changes: 0 additions & 166 deletions public/manifest.json

This file was deleted.

8 changes: 6 additions & 2 deletions src/app/(main)/discover/(detail)/_layout/Desktop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ const Layout = ({ children }: PropsWithChildren) => {
align={'center'}
flex={1}
padding={24}
style={{ overflowX: 'hidden', overflowY: 'scroll', position: 'relative' }}
style={{ overflowX: 'hidden', overflowY: 'auto', position: 'relative' }}
width={'100%'}
>
<Flexbox gap={24} style={{ maxWidth: MAX_WIDTH, position: 'relative' }} width={'100%'}>
<Flexbox
gap={24}
style={{ maxWidth: MAX_WIDTH, minHeight: '100%', position: 'relative' }}
width={'100%'}
>
{children}
</Flexbox>
</Flexbox>
Expand Down
2 changes: 1 addition & 1 deletion src/app/(main)/discover/(detail)/assistant/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const generateMetadata = async ({ params, searchParams }: Props) => {

const discoverService = new DiscoverService();
const data = await discoverService.getAssistantById(locale, identifier);
if (!data) return notFound();
if (!data) return;

const { meta, createdAt, homepage, author } = data;

Expand Down
2 changes: 1 addition & 1 deletion src/app/(main)/discover/(detail)/model/[...slugs]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const generateMetadata = async ({ params, searchParams }: Props) => {

const discoverService = new DiscoverService();
const data = await discoverService.getModelById(locale, identifier);
if (!data) return notFound();
if (!data) return;

const { meta, createdAt, providers } = data;

Expand Down
2 changes: 1 addition & 1 deletion src/app/(main)/discover/(detail)/plugin/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const generateMetadata = async ({ params, searchParams }: Props) => {

const discoverService = new DiscoverService();
const data = await discoverService.getPluginById(locale, identifier);
if (!data) return notFound();
if (!data) return;

const { meta, createdAt, homepage, author } = data;

Expand Down
2 changes: 1 addition & 1 deletion src/app/(main)/discover/(detail)/provider/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const generateMetadata = async ({ params, searchParams }: Props) => {

const discoverService = new DiscoverService();
const data = await discoverService.getProviderById(locale, identifier);
if (!data) return notFound();
if (!data) return;

const { meta, createdAt, models } = data;

Expand Down
86 changes: 86 additions & 0 deletions src/app/manifest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { kebabCase } from 'lodash-es';
import type { MetadataRoute } from 'next';

import { BRANDING_LOGO_URL, BRANDING_NAME } from '@/const/branding';
import { manifestModule } from '@/server/manifest';
import { translation } from '@/server/translation';

const manifest = async (): Promise<MetadataRoute.Manifest | any> => {
const { t } = await translation('metadata');

return manifestModule.generate({
description: t('chat.description', { appName: BRANDING_NAME }),
icons: [
{
purpose: 'any',
sizes: '192x192',
url: '/icons/icon-192x192.png',
},
{
purpose: 'maskable',
sizes: '192x192',
url: '/icons/icon-192x192.maskable.png',
},
{
purpose: 'any',
sizes: '512x512',
url: '/icons/icon-512x512.png',
},
{
purpose: 'maskable',
sizes: '512x512',
url: '/icons/icon-512x512.maskable.png',
},
],
id: kebabCase(BRANDING_NAME),
name: BRANDING_NAME,
screenshots: BRANDING_LOGO_URL
? []
: [
{
form_factor: 'narrow',
url: '/screenshots/shot-1.mobile.png',
},
{
form_factor: 'narrow',
url: '/screenshots/shot-2.mobile.png',
},
{
form_factor: 'narrow',
sizes: '640x1138',

url: '/screenshots/shot-3.mobile.png',
},
{
form_factor: 'narrow',
url: '/screenshots/shot-4.mobile.png',
},
{
form_factor: 'narrow',
url: '/screenshots/shot-5.mobile.png',
},
{
form_factor: 'wide',
url: '/screenshots/shot-1.desktop.png',
},
{
form_factor: 'wide',
url: '/screenshots/shot-2.desktop.png',
},
{
form_factor: 'wide',
url: '/screenshots/shot-3.desktop.png',
},
{
form_factor: 'wide',
url: '/screenshots/shot-4.desktop.png',
},
{
form_factor: 'wide',
url: '/screenshots/shot-5.desktop.png',
},
],
});
};

export default manifest;
6 changes: 5 additions & 1 deletion src/features/PWAInstall/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ const PWAInstall = memo(() => {

if (isPWA) return null;
return (
<PWA description={t('chat.description', { appName: BRANDING_NAME })} id={PWA_INSTALL_ID} />
<PWA
description={t('chat.description', { appName: BRANDING_NAME })}
id={PWA_INSTALL_ID}
manifest-url={'/manifest.webmanifest'}
/>
);
});

Expand Down
Loading

0 comments on commit 8afb4e2

Please sign in to comment.