From 1b80809763f1aa50ab545fb9a3a1b61b08da9d17 Mon Sep 17 00:00:00 2001
From: jingyang <72259332+zjy365@users.noreply.github.com>
Date: Mon, 20 May 2024 17:14:22 +0800
Subject: [PATCH] fix github stars (#34)
* fix github stars
Signed-off-by: jingyang <3161362058@qq.com>
* fix github stars
---------
Signed-off-by: jingyang <3161362058@qq.com>
---
projects/fastgpt/app/[[...lang]]/page.tsx | 48 ++++++++++---------
projects/fastgpt/components/home/CTA.tsx | 16 +++----
.../fastgpt/components/home/CTAButton.tsx | 12 +++--
projects/fastgpt/components/home/Hero.tsx | 17 ++++---
4 files changed, 48 insertions(+), 45 deletions(-)
diff --git a/projects/fastgpt/app/[[...lang]]/page.tsx b/projects/fastgpt/app/[[...lang]]/page.tsx
index 163cd40..7d27fe9 100644
--- a/projects/fastgpt/app/[[...lang]]/page.tsx
+++ b/projects/fastgpt/app/[[...lang]]/page.tsx
@@ -1,31 +1,34 @@
-import Header from "@/components/header/Header";
-import Ability from "@/components/home/Ability";
-import CTA from "@/components/home/CTA";
-import FAQ from "@/components/home/FAQ";
-import Feature from "@/components/home/Feature";
-import Hero from "@/components/home/Hero";
-import Pricing from "@/components/home/Pricing";
-import SocialProof from "@/components/home/SocialProof";
-import VideoPlayer from "@/components/home/Video";
-import { defaultLocale, getDictionary, localeNames } from "@/lib/i18n";
-
-export default async function LangHome({
- params: { lang },
-}: {
- params: { lang?: string[] };
-}) {
- let langName =
- lang && lang[0] && lang[0] !== "index" ? lang[0] : defaultLocale;
+import Header from '@/components/header/Header';
+import Ability from '@/components/home/Ability';
+import CTA from '@/components/home/CTA';
+import FAQ from '@/components/home/FAQ';
+import Feature from '@/components/home/Feature';
+import Hero from '@/components/home/Hero';
+import Pricing from '@/components/home/Pricing';
+import SocialProof from '@/components/home/SocialProof';
+import VideoPlayer from '@/components/home/Video';
+import { defaultLocale, getDictionary, localeNames } from '@/lib/i18n';
+
+export default async function LangHome({ params: { lang } }: { params: { lang?: string[] } }) {
+ let langName = lang && lang[0] && lang[0] !== 'index' ? lang[0] : defaultLocale;
const dict = await getDictionary(langName);
-
+ let stars = 13 * 1000;
+ try {
+ const { stargazers_count } = await (
+ await fetch('https://api.github.com/repos/labring/FastGPT')
+ ).json();
+ if (stargazers_count) {
+ stars = stargazers_count;
+ }
+ } catch (error) {}
return (
<>
{/* Hero Section */}
-
+
{/* Can be used to display technology stack, partners, project honors, etc. */}
{/**/}
@@ -43,7 +46,7 @@ export default async function LangHome({
{/* CTA (Call to Action) */}
-
+
>
);
@@ -51,6 +54,5 @@ export default async function LangHome({
export async function generateStaticParams() {
const keys = Object.keys(localeNames).map((lang) => ({ lang: [lang] }));
- return [{ lang: [""] }, ...keys];
+ return [{ lang: [''] }, ...keys];
}
-
diff --git a/projects/fastgpt/components/home/CTA.tsx b/projects/fastgpt/components/home/CTA.tsx
index 11e68eb..72bb921 100644
--- a/projects/fastgpt/components/home/CTA.tsx
+++ b/projects/fastgpt/components/home/CTA.tsx
@@ -1,8 +1,8 @@
/* eslint-disable react/no-unescaped-entities */
-import CTAButton from "@/components/home/CTAButton";
-import { RoughNotation } from "react-rough-notation";
+import CTAButton from '@/components/home/CTAButton';
+import { RoughNotation } from 'react-rough-notation';
-const CTA = ({ locale, CTALocale }: { locale: any; CTALocale: any; }) => {
+const CTA = ({ locale, CTALocale, stars }: { locale: any; CTALocale: any; stars: number }) => {
return (
@@ -10,19 +10,19 @@ const CTA = ({ locale, CTALocale }: { locale: any; CTALocale: any; }) => {
{locale.description1}
- {" "}
- {locale.description2}{" "}
+
+ {locale.description2}
{locale.description3}
- {" "}
- {locale.description4}{" "}
+
+ {locale.description4}
{locale.description5}
{locale.description6}
-
+
);
};
diff --git a/projects/fastgpt/components/home/CTAButton.tsx b/projects/fastgpt/components/home/CTAButton.tsx
index d1fb8cd..ebf4cea 100644
--- a/projects/fastgpt/components/home/CTAButton.tsx
+++ b/projects/fastgpt/components/home/CTAButton.tsx
@@ -4,20 +4,22 @@ import { RocketIcon } from 'lucide-react';
import Link from 'next/link';
import { useEffect, useState } from 'react';
-const CTAButton = ({ locale }: { locale: any }) => {
- const [stars, setStars] = useState(13 * 1000);
+const CTAButton = ({ locale, stars: initialStars }: { locale: any; stars: number }) => {
+ const [stars, setStars] = useState(initialStars);
useEffect(() => {
const getStars = async () => {
try {
const { stargazers_count } = await (
- await fetch('https://api.github.com/repos/labring/FastGPT', { cache: 'force-cache' })
+ await fetch('https://api.github.com/repos/labring/FastGPT')
).json();
- setStars(stargazers_count);
+ if (stargazers_count && stargazers_count !== initialStars) {
+ setStars(stargazers_count);
+ }
} catch (error) {}
};
getStars();
- }, []);
+ }, [initialStars]);
return (
diff --git a/projects/fastgpt/components/home/Hero.tsx b/projects/fastgpt/components/home/Hero.tsx
index e303097..6cd1355 100644
--- a/projects/fastgpt/components/home/Hero.tsx
+++ b/projects/fastgpt/components/home/Hero.tsx
@@ -1,10 +1,9 @@
-"use client";
-import { LineText } from "@/components/LineText";
-import CTAButton from "@/components/home/CTAButton";
-import { motion } from "framer-motion";
-
-const Hero = ({ locale, CTALocale }: { locale: any; CTALocale: any; }) => {
+'use client';
+import { LineText } from '@/components/LineText';
+import CTAButton from '@/components/home/CTAButton';
+import { motion } from 'framer-motion';
+const Hero = ({ locale, CTALocale, stars }: { locale: any; CTALocale: any; stars: number }) => {
return (
<>
{
duration: 0.3,
ease: [0, 0.71, 0.2, 1],
scale: {
- type: "tween", // tween spring
+ type: 'tween' // tween spring
// damping: 10, // if spring
// stiffness: 50, // if spring
// restDelta: 0.001, // if spring
- },
+ }
}}
>
@@ -31,7 +30,7 @@ const Hero = ({ locale, CTALocale }: { locale: any; CTALocale: any; }) => {
-
+
>
);
};