From 92a00c5cca9e359ceb5fb930589be87e33ada93c Mon Sep 17 00:00:00 2001 From: chenxc <> Date: Mon, 15 Jul 2024 13:53:32 +0800 Subject: [PATCH] feat(side config): add SITE_TITLE,SITE_DESCRIPTION and SITE_LOGO_URL as environment variable --- .env.template | 6 ++++-- .github/workflows/docker.yml | 2 +- app/components/exporter.tsx | 9 ++++----- app/components/sidebar.tsx | 14 ++++++++------ app/config/server.ts | 23 +++++++++++++---------- app/layout.tsx | 9 ++++++--- app/store/update.ts | 6 ++++-- 7 files changed, 40 insertions(+), 29 deletions(-) diff --git a/.env.template b/.env.template index 4a6fe3fef..679332ef0 100644 --- a/.env.template +++ b/.env.template @@ -63,8 +63,10 @@ ANTHROPIC_URL= WHITE_WEBDEV_ENDPOINTS= ### custom sidebar title.(optional) -SIDEBAR_TITLE= +SITE_TITLE= ### custom sidebar subtitle.(optional) -SIDEBAR_SUBTITLE= +SITE_DESCRIPTION= +## custom sidebar logo url.(optional) +SITE_LOGO_URL= diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index b3a0405a8..963244c33 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -25,7 +25,7 @@ jobs: id: meta uses: docker/metadata-action@v4 with: - images: 195658/chatgpt-next-web + images: yidadaa/chatgpt-next-web tags: | type=raw,value=latest type=ref,event=tag diff --git a/app/components/exporter.tsx b/app/components/exporter.tsx index 948807d4c..57259aa00 100644 --- a/app/components/exporter.tsx +++ b/app/components/exporter.tsx @@ -40,6 +40,7 @@ import { EXPORT_MESSAGE_CLASS_NAME } from "../constant"; import { getClientConfig } from "../config/client"; import { type ClientApi, getClientApi } from "../client/api"; import { getMessageTextContent } from "../utils"; +import { getServerSideConfig } from "@/app/config/server"; const Markdown = dynamic(async () => (await import("./markdown")).Markdown, { loading: () => , @@ -515,7 +516,7 @@ export function ImagePreviewer(props: { dom.innerHTML = dom.innerHTML; // Refresh the content of the preview by resetting its HTML for fix a bug glitching } }; - + const { siteTitle, siteDescription } = getServerSideConfig(); return (
-
NextChat
-
- github.com/Yidadaa/ChatGPT-Next-Web -
+
{siteTitle}
+
{siteDescription}
& diff --git a/app/components/sidebar.tsx b/app/components/sidebar.tsx index c68aacccf..13d22a118 100644 --- a/app/components/sidebar.tsx +++ b/app/components/sidebar.tsx @@ -140,7 +140,7 @@ export function SideBar(props: { className?: string }) { () => isIOS() && isMobileScreen, [isMobileScreen], ); - const serverConfig = getServerSideConfig(); + const { siteTitle, siteDescription, siteLogURL } = getServerSideConfig(); useHotKey(); return ( @@ -155,13 +155,15 @@ export function SideBar(props: { className?: string }) { >
- {serverConfig.sidebarTitle} -
-
- {serverConfig.sidebarSubTitle} + {siteTitle}
+
{siteDescription}
- + {!!siteLogURL ? ( + + ) : ( + + )}
diff --git a/app/config/server.ts b/app/config/server.ts index fc6de1157..8ad8a4bf9 100644 --- a/app/config/server.ts +++ b/app/config/server.ts @@ -56,10 +56,11 @@ declare global { // custom template for preprocessing user input DEFAULT_INPUT_TEMPLATE?: string; - // custom sidebar title - SIDEBAR_TITLE?: string; - // custom sidebar sub-title - SIDEBAR_SUB_TITLE?: string; + // custom site title + SITE_TITLE?: string; + // custom site description + SITE_DESCRIPTION?: string; + SITE_LOGO_URL?: string; } } } @@ -129,10 +130,11 @@ export const getServerSideConfig = () => { const allowedWebDevEndpoints = ( process.env.WHITE_WEBDEV_ENDPOINTS ?? "" ).split(","); - // custom title - const sidebarTitle = process.env.SIDEBAR_TITLE ?? "NextChat"; - const sidebarSubTitle = - process.env.SIDEBAR_SUB_TITLE ?? "Build your own AI assistant."; + // custom site + const siteTitle = process.env.SITE_TITLE ?? "NextChat"; + const siteDescription = + process.env.SITE_DESCRIPTION ?? "Build your own AI assistant."; + const siteLogURL = process.env.SITE_LOGO_URL ?? ""; return { baseUrl: process.env.BASE_URL, apiKey: getApiKey(process.env.OPENAI_API_KEY), @@ -181,7 +183,8 @@ export const getServerSideConfig = () => { customModels, defaultModel, allowedWebDevEndpoints, - sidebarTitle, - sidebarSubTitle, + siteTitle, + siteDescription, + siteLogURL, }; }; diff --git a/app/layout.tsx b/app/layout.tsx index 637b4556b..787158cca 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -10,10 +10,10 @@ import { GoogleTagManager } from "@next/third-parties/google"; const serverConfig = getServerSideConfig(); export const metadata: Metadata = { - title: "NextChat", + title: serverConfig.siteTitle, description: "Your personal ChatGPT Chat Bot.", appleWebApp: { - title: "NextChat", + title: serverConfig.siteTitle, statusBarStyle: "default", }, }; @@ -37,7 +37,10 @@ export default function RootLayout({ - + diff --git a/app/store/update.ts b/app/store/update.ts index 7253caffc..a3f02aa24 100644 --- a/app/store/update.ts +++ b/app/store/update.ts @@ -11,9 +11,11 @@ import Locale from "../locales"; import { use } from "react"; import { useAppConfig } from "."; import { ClientApi } from "../client/api"; +import { getServerSideConfig } from "@/app/config/server"; const ONE_MINUTE = 60 * 1000; const isApp = !!getClientConfig()?.isApp; +const serverConfig = getServerSideConfig(); function formatVersionDate(t: string) { const d = new Date(+t); @@ -106,7 +108,7 @@ export const useUpdateStore = createPersistStore( if (version === remoteId) { // Show a notification using Tauri window.__TAURI__?.notification.sendNotification({ - title: "NextChat", + title: `${serverConfig.siteTitle}`, body: `${Locale.Settings.Update.IsLatest}`, icon: `${ChatGptIcon.src}`, sound: "Default", @@ -116,7 +118,7 @@ export const useUpdateStore = createPersistStore( Locale.Settings.Update.FoundUpdate(`${remoteId}`); // Show a notification for the new version using Tauri window.__TAURI__?.notification.sendNotification({ - title: "NextChat", + title: `${serverConfig.siteTitle}`, body: updateMessage, icon: `${ChatGptIcon.src}`, sound: "Default",