fix: 修复图片显示问题,添加whitenoise优化静态文件性能
Some checks failed
Deploy to Server / deploy (push) Has been cancelled

This commit is contained in:
爽哒哒
2026-03-21 12:18:51 +08:00
parent 68ebf7f100
commit 555b5badbf
6 changed files with 29 additions and 32 deletions

View File

@@ -22,11 +22,10 @@ import 'github-markdown-css/github-markdown-dark.css';
*/
const getImageUrl = (url) => {
if (!url) return '';
if (url.startsWith('http') || url.startsWith('//')) return url;
const apiUrl = import.meta.env.VITE_API_URL || 'http://localhost:8000/api';
// Remove /api suffix if present to get the root URL for media files
const baseUrl = apiUrl.replace(/\/api\/?$/, '');
return `${baseUrl}${url}`;
if (url.startsWith('http') || url.startsWith('//')) {
try { return new URL(url).pathname; } catch { return url; }
}
return url;
};
const { Title, Paragraph } = Typography;

View File

@@ -3,7 +3,7 @@ import { Card, Row, Col, Tag, Button, Spin, Typography, Carousel } from 'antd';
import { RocketOutlined, RightOutlined, LeftOutlined } from '@ant-design/icons';
import { useNavigate } from 'react-router-dom';
import { motion } from 'framer-motion';
import { getConfigs, getHomePageConfig, getCompetitions, getActivities } from '../api';
import { getHomePageConfig, getCompetitions, getActivities } from '../api';
import './Home.css';
const { Title, Paragraph } = Typography;
@@ -19,7 +19,7 @@ const getImageUrl = (url) => {
const Home = () => {
const [products, setProducts] = useState([]);
const [loading, setLoading] = useState(true);
const [loading, setLoading] = useState(false);
const [typedText, setTypedText] = useState('');
const [isTypingComplete, setIsTypingComplete] = useState(false);
const [currentSlide, setCurrentSlide] = useState(0);
@@ -38,7 +38,6 @@ const Home = () => {
const carouselRef3 = useRef(null);
useEffect(() => {
fetchProducts();
fetchHomePageConfig();
fetchCompetitions();
fetchActivities();
@@ -64,17 +63,6 @@ const Home = () => {
return () => clearInterval(mainTypingInterval);
}, [homeConfig?.main_title]);
const fetchProducts = async () => {
try {
const response = await getConfigs();
setProducts(response.data);
} catch (error) {
console.error('Failed to fetch products:', error);
} finally {
setLoading(false);
}
};
const fetchHomePageConfig = async () => {
try {
const response = await getHomePageConfig();