Skip to content

Commit 15d8729

Browse files
authored
home (#154)
* home * home
1 parent d9bb26d commit 15d8729

9 files changed

Lines changed: 64 additions & 21 deletions

File tree

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ ARG NEXT_PUBLIC_RYBBIT_TONGJI
1717
ARG NEXT_PUBLIC_RYBBIT_TONGJI_SITEID
1818
ARG NEXT_PUBLIC_CUSTOM_PLAN_URL
1919
ARG NEXT_PUBLIC_FAQ
20+
ARG NEXT_PUBLIC_DEFAULT_LOCALE
2021

2122
ENV NEXT_PUBLIC_BAIDU_TONGJI=$NEXT_PUBLIC_BAIDU_TONGJI
2223
ENV NEXT_PUBLIC_BAIDU_KEY=$NEXT_PUBLIC_BAIDU_KEY
@@ -28,14 +29,14 @@ ENV NEXT_PUBLIC_RYBBIT_TONGJI=$NEXT_PUBLIC_RYBBIT_TONGJI
2829
ENV NEXT_PUBLIC_RYBBIT_TONGJI_SITEID=$NEXT_PUBLIC_RYBBIT_TONGJI_SITEID
2930
ENV NEXT_PUBLIC_CUSTOM_PLAN_URL=$NEXT_PUBLIC_CUSTOM_PLAN_URL
3031
ENV NEXT_PUBLIC_FAQ=$NEXT_PUBLIC_FAQ
32+
ENV NEXT_PUBLIC_DEFAULT_LOCALE=${NEXT_PUBLIC_DEFAULT_LOCALE:-zh}
3133

3234
# copy packages and one project
3335
COPY . ./
3436

3537
# Replace URLs in files (fix sed -i syntax for Alpine Linux)
3638
RUN find . -type f -name "*.ts" -o -name "*.tsx" -o -name "*.js" -o -name "*.jsx" -o -name "*.json" | xargs grep -l "https://doc.fastgpt.io" | xargs -r sed -i "s#https://doc.fastgpt.io#https://doc.fastgpt.cn#g"
3739
RUN find . -type f -name "*.ts" -o -name "*.tsx" -o -name "*.js" -o -name "*.jsx" -o -name "*.json" | xargs grep -l "https://cloud.fastgpt.io" | xargs -r sed -i "s#https://cloud.fastgpt.io#https://cloud.fastgpt.cn#g"
38-
RUN if [ -f src/lib/i18n.ts ]; then sed -i "s/defaultLocale = \"en\"/defaultLocale = \"zh\"/g" src/lib/i18n.ts; fi
3940

4041
RUN npm install
4142
RUN npm run build

public/fastgpt-original.mp4

-68.9 MB
Binary file not shown.

public/fastgpt.mp4

-31.1 MB
Binary file not shown.

public/fastgpt.webm

-38.5 MB
Binary file not shown.

src/app/layout.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import RybbitAnalytics from '@/app/RybbitAnalytics';
55
import { ThemeProvider } from '@/components/ThemeProvider';
66
import { siteConfig } from '@/config/site';
77
import { cn } from '@/lib/utils';
8+
import { defaultLocale } from '@/lib/i18n';
89
import { htmlLangScript } from '@/lib/htmlLang';
910
import '@/styles/globals.css';
1011
import '@/styles/loading.css';
@@ -50,7 +51,7 @@ export default function RootLayout({
5051
children: React.ReactNode;
5152
}) {
5253
return (
53-
<html lang="en" suppressHydrationWarning>
54+
<html lang={defaultLocale} suppressHydrationWarning>
5455
<head>
5556
{/* Synchronously set html[lang] from URL path — must run before hydration */}
5657
<script dangerouslySetInnerHTML={{ __html: htmlLangScript }} />

src/app/page.tsx

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,45 @@
1-
'use client';
1+
import Ability from '@/components/home/Ability';
2+
import CTA from '@/components/home/CTA';
3+
import FAQ from '@/components/home/FAQ';
4+
import Feature from '@/components/home/Feature';
5+
import Hero from '@/components/home/Hero';
6+
import VideoPlayer from '@/components/home/Video';
7+
import Header from '@/components/header/Header';
8+
import JsonLd from '@/components/JsonLd';
9+
import { defaultLocale, getDictionary } from '@/lib/i18n';
10+
import { getAlternates } from '@/lib/seo';
11+
import { getGitHubStars } from '@/lib/utils';
12+
import { siteConfig, siteConfigZh, siteConfigJa } from '@/config/site';
13+
import { Metadata } from 'next';
214

3-
import { useEffect } from 'react';
4-
import { defaultLocale, localeNames } from '@/lib/i18n';
15+
const configMap: Record<string, typeof siteConfig> = { en: siteConfig, zh: siteConfigZh, ja: siteConfigJa };
16+
const rootConfig = configMap[defaultLocale] || siteConfig;
517

6-
export default function RootPage() {
7-
useEffect(() => {
8-
const storedLang = localStorage.getItem('preferredLang');
9-
const lang =
10-
storedLang && Object.keys(localeNames).includes(storedLang)
11-
? storedLang
12-
: defaultLocale;
13-
window.location.replace(`/${lang}`);
14-
}, []);
18+
export const metadata: Metadata = {
19+
title: rootConfig.title,
20+
description: rootConfig.description,
21+
keywords: rootConfig.keywords,
22+
alternates: getAlternates(defaultLocale, '')
23+
};
1524

16-
return null;
25+
export default async function RootPage() {
26+
const dict = await getDictionary(defaultLocale);
27+
const stars = await getGitHubStars();
28+
29+
return (
30+
<>
31+
<JsonLd lang={defaultLocale} />
32+
<Header dict={dict} CTALocale={dict.CTAButton} />
33+
<main className="flex flex-col items-center mt-12 sm:mt-14 lg:mt-20">
34+
<div className="mx-4 sm:mx-6 md:mx-12 xl:mx-[60px] 2xl:max-w-7xl 2xl:mx-auto flex flex-col items-center margin-top-40">
35+
<Hero locale={dict.Hero} CTALocale={dict.CTAButton} stars={stars} />
36+
<VideoPlayer locale={dict.Video} dict={dict} />
37+
<Ability id="Ability" locale={dict.Ability} langName={defaultLocale} />
38+
<Feature id="Features" locale={dict.Feature} langName={defaultLocale} />
39+
<FAQ id="FAQ" locale={dict.FAQ} langName={defaultLocale} />
40+
<CTA locale={dict.CTA} CTALocale={dict.CTAButton} stars={stars} />
41+
</div>
42+
</main>
43+
</>
44+
);
1745
}

src/components/home/Video.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ const VideoPlayer = ({
9595
data-poster="/images/hero/zh/fastgpt-demo.jpg"
9696
>
9797
<source
98-
src="/fastgpt.webm"
98+
src="https://oss.laf.run/otnvvf-imgs/fastgpt.webm"
9999
type="video/webm"
100100
/>
101101
<source
102-
src="/fastgpt.mp4"
102+
src="https://oss.laf.run/otnvvf-imgs/fastgpt.mp4"
103103
type="video/mp4"
104104
/>
105105
</video>

src/lib/htmlLang.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,28 @@
33
* This runs before React hydration, so search engines and browsers see the correct lang.
44
* Must be used as a dangerouslySetInnerHTML script in the root layout <head>.
55
*
6-
* Root / defaults to 'en'; /zh, /ja paths override accordingly.
7-
* Priority: URL lang > localStorage preferredLang > 'en'
6+
* Root / redirects to stored language preference or the build-time default locale.
7+
* /zh, /ja, /en paths are respected as-is.
88
*/
9+
10+
const buildDefaultLocale = process.env.NEXT_PUBLIC_DEFAULT_LOCALE || 'en';
11+
912
export const htmlLangScript = `
1013
(function() {
1114
var path = window.location.pathname;
12-
var lang = 'en';
15+
var lang = '${buildDefaultLocale}';
1316
if (path.startsWith('/zh')) lang = 'zh';
1417
else if (path.startsWith('/ja')) lang = 'ja';
18+
else if (path.startsWith('/en')) lang = 'en';
1519
document.documentElement.lang = lang;
20+
21+
if (path === '/') {
22+
var locales = ['en', 'zh', 'ja'];
23+
var stored = '';
24+
try { stored = localStorage.getItem('preferredLang') || ''; } catch(e) {}
25+
if (stored && locales.indexOf(stored) !== -1) {
26+
window.location.replace('/' + stored);
27+
}
28+
}
1629
})();
1730
`.trim();

src/lib/i18n.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const localeNames: any = {
77
zh: '中文',
88
ja: '日本語'
99
};
10-
export const defaultLocale = 'en';
10+
export const defaultLocale = process.env.NEXT_PUBLIC_DEFAULT_LOCALE || 'en';
1111

1212
// If you wish to automatically redirect users to a URL that matches their browser's language setting,
1313
// you can use the `getLocale` to get the browser's language.

0 commit comments

Comments
 (0)