blob: 8ed1ac9b33215cc7d03f70d78c64c386604e79be (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
import fs from 'node:fs/promises'
import randomIndex from './random-index'
/**
* getHeroImg
* @returns url of random Hero Image from './public/images'
*/
export default async function getHeroImg(){
try {
const data =[]
const paths =await fs.readdir('./public/images',{filesOnly:true})
paths.map(path=>data.push(`/images/${path}`))
return data[randomIndex(paths.length)]
} catch (error) {
console.log(error)
}
}
|