Skip to content

Commit

Permalink
♻️ refactor: refactor the SITE_URL to APP_URL (lobehub#3504)
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx authored Aug 18, 2024
1 parent a40ac66 commit 46bdcea
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
5 changes: 2 additions & 3 deletions src/app/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Metadata } from 'next';

import { appEnv, getAppConfig } from '@/config/app';
import { appEnv } from '@/config/app';
import { OFFICIAL_URL, OG_URL } from '@/const/url';
import { translation } from '@/server/translation';

const title = 'LobeChat';

const { SITE_URL = OFFICIAL_URL } = getAppConfig();
const BASE_PATH = appEnv.NEXT_PUBLIC_BASE_PATH;

// if there is a base path, then we don't need the manifest
Expand All @@ -27,7 +26,7 @@ export const generateMetadata = async (): Promise<Metadata> => {
shortcut: '/favicon-32x32.ico?v=1',
},
manifest: noManifest ? undefined : '/manifest.json',
metadataBase: new URL(SITE_URL),
metadataBase: new URL(OFFICIAL_URL),
openGraph: {
description: t('chat.description'),
images: [
Expand Down
4 changes: 2 additions & 2 deletions src/config/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const getAppConfig = () => {
PLUGINS_INDEX_URL: z.string().url(),
PLUGIN_SETTINGS: z.string().optional(),

SITE_URL: z.string().optional(),
APP_URL: z.string().optional(),
},
runtimeEnv: {
NEXT_PUBLIC_BASE_PATH: process.env.NEXT_PUBLIC_BASE_PATH || '',
Expand All @@ -52,7 +52,7 @@ export const getAppConfig = () => {
: 'https://chat-plugins.lobehub.com',

PLUGIN_SETTINGS: process.env.PLUGIN_SETTINGS,
SITE_URL: process.env.SITE_URL,
APP_URL: process.env.APP_URL,
},
});
};
Expand Down
18 changes: 8 additions & 10 deletions src/server/ld.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import urlJoin from 'url-join';

import { getAppConfig } from '@/config/app';
import { EMAIL_BUSINESS, EMAIL_SUPPORT, OFFICIAL_SITE, OFFICIAL_URL, X } from '@/const/url';

import pkg from '../../package.json';

const { SITE_URL = OFFICIAL_URL } = getAppConfig();
const LAST_MODIFIED = new Date().toISOString();
export const AUTHOR_LIST = {
arvinxx: {
Expand Down Expand Up @@ -70,7 +68,7 @@ class Ld {

genOrganization() {
return {
'@id': this.getId(SITE_URL, '#organization'),
'@id': this.getId(OFFICIAL_URL, '#organization'),
'@type': 'Organization',
'alternateName': 'LobeChat',
'contactPoint': {
Expand Down Expand Up @@ -102,7 +100,7 @@ class Ld {

getAuthors(ids: string[] = []) {
const defaultAuthor = {
'@id': this.getId(SITE_URL, '#organization'),
'@id': this.getId(OFFICIAL_URL, '#organization'),
'@type': 'Organization',
};
if (!ids || ids.length === 0) return defaultAuthor;
Expand Down Expand Up @@ -142,7 +140,7 @@ class Ld {
'@id': fixedUrl,
'@type': 'WebPage',
'about': {
'@id': this.getId(SITE_URL, '#organization'),
'@id': this.getId(OFFICIAL_URL, '#organization'),
},
'breadcrumbs': {
'@id': this.getId(fixedUrl, '#breadcrumb'),
Expand All @@ -155,7 +153,7 @@ class Ld {
},
'inLanguage': 'en-US',
'isPartOf': {
'@id': this.getId(SITE_URL, '#website'),
'@id': this.getId(OFFICIAL_URL, '#website'),
},
'name': this.fixTitle(title),
'primaryImageOfPage': {
Expand Down Expand Up @@ -188,15 +186,15 @@ class Ld {

genWebSite() {
const baseInfo: any = {
'@id': this.getId(SITE_URL, '#website'),
'@id': this.getId(OFFICIAL_URL, '#website'),
'@type': 'WebSite',
'description': pkg.description,
'inLanguage': 'en-US',
'name': 'LobeChat',
'publisher': {
'@id': this.getId(SITE_URL, '#organization'),
'@id': this.getId(OFFICIAL_URL, '#organization'),
},
'url': SITE_URL,
'url': OFFICIAL_URL,
};

return baseInfo;
Expand All @@ -211,7 +209,7 @@ class Ld {
}

private fixUrl(url: string) {
return urlJoin(SITE_URL, url);
return urlJoin(OFFICIAL_URL, url);
}
}

Expand Down

0 comments on commit 46bdcea

Please sign in to comment.