fix: homepage '文档' nav link now uses dynamic same-origin docs URL instead of hardcoded docs.new-api.cc

This commit is contained in:
xiezhouwei 2026-06-22 09:09:02 +08:00
parent 59cc502e6e
commit 9f47782442
1 changed files with 11 additions and 4 deletions

View File

@ -17,10 +17,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import React, { useState, useEffect, useCallback, useRef } from 'react';
import React, { useState, useEffect, useCallback, useRef, useMemo } from 'react';
import { Link, useNavigate } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import { Copy, Check, Code, Terminal, FileCode, Box, Grid3X3, Play, Trophy, PieChart, BookOpen, Search, Sun, Moon, Monitor, Languages } from 'lucide-react';
import { mapWebLanguageToDocsLocale } from '../../helpers/docsLink';
/* ==================================================================
@ -139,7 +140,7 @@ function HomeLanguageSelector() {
}
function HeroSection() {
const { t } = useTranslation();
const { t, i18n } = useTranslation();
const [copied, setCopied] = useState(false);
const navigate = useNavigate();
const copyCmd = useCallback(() => {
@ -147,6 +148,12 @@ function HeroSection() {
setCopied(true);
setTimeout(() => setCopied(false), 1500);
}, []);
const docsUrl = useMemo(() => {
const locale = mapWebLanguageToDocsLocale(i18n.language);
return `/${locale}/docs`;
}, [i18n.language]);
return (
<section className="relative bg-black text-white overflow-hidden">
<div className="absolute inset-0 pointer-events-none opacity-[0.04]" style={{ backgroundImage: "radial-gradient(circle, white 1px, transparent 1px)", backgroundSize: "24px 24px" }} />
@ -162,12 +169,12 @@ function HeroSection() {
{[
{ key: "model", label: "模型", icon: <Box size={16} />, to: "/pricing" },
{ key: "benchmark", label: "评测", icon: <Trophy size={16} />, to: "/benchmarks" },
{ key: "docs", label: "文档", icon: <BookOpen size={16} />, to: "https://docs.new-api.cc", external: true },
{ key: "docs", label: "文档", icon: <BookOpen size={16} />, to: docsUrl, external: true },
{ key: "console", label: "控制台", icon: <Grid3X3 size={16} />, to: "/console" },
].map((item) => {
const linkClass = "inline-flex items-center gap-1.5 px-3 py-1.5 text-[14px] rounded-md transition-colors duration-150 text-white/60 hover:text-white";
if (item.external) {
return <a key={item.key} href={item.to} target="_blank" rel="noopener noreferrer" className={linkClass}>{item.icon}<span className="hidden sm:inline">{t(item.label)}</span></a>;
return <a key={item.key} href={item.to} className={linkClass}>{item.icon}<span className="hidden sm:inline">{t(item.label)}</span></a>;
}
return <Link key={item.key} to={item.to} className={linkClass}>{item.icon}<span className="hidden sm:inline">{t(item.label)}</span></Link>;
})}