mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
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:
@@ -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 = () => {
|
||||
|
||||
Reference in New Issue
Block a user