refactor(board header): use dynamic banner discovery with Vite glob imports

Replaced hardcoded banner array with Vite's import.meta.glob to automatically discover all banner files at build time. Now supports unlimited banners without code changes. Works across all platforms (web, Electron, Android).
This commit is contained in:
plebeius
2025-11-01 16:46:51 +01:00
parent c12fa7465d
commit e350311308
+5 -15
View File
@@ -13,24 +13,14 @@ import { shouldShowSnow } from '../../lib/snow';
import Tooltip from '../tooltip';
import _ from 'lodash';
const totalBanners = 4;
// Dynamically import all banner images at build time
const bannerModules = import.meta.glob('/public/assets/banners/banner-*.{jpg,jpeg,gif,png}', { eager: true, as: 'url' });
const bannerPaths = Object.keys(bannerModules).map((path) => path.replace('/public/', ''));
const ImageBanner = () => {
const [index] = useState(() => Math.floor(Math.random() * totalBanners) + 1);
const jpg = `assets/banners/banner-${index}.jpg`;
const gif = `assets/banners/banner-${index}.gif`;
const [banner] = useState(() => bannerPaths[Math.floor(Math.random() * bannerPaths.length)]);
return (
<img
src={jpg}
alt=''
onError={(e) => {
const img = e.currentTarget;
img.onerror = null;
img.src = gif;
}}
/>
);
return <img src={banner} alt='' />;
};
const BoardHeader = () => {