From d321d8366b597e46ff8e3fc63d17622a9297505c Mon Sep 17 00:00:00 2001 From: aFuzzyBear Date: Tue, 10 Aug 2021 01:24:25 +0100 Subject: Adds examples page --- docs/src/components/Examples/Functions/get-hero-img.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 docs/src/components/Examples/Functions/get-hero-img.js (limited to 'docs/src/components/Examples/Functions/get-hero-img.js') diff --git a/docs/src/components/Examples/Functions/get-hero-img.js b/docs/src/components/Examples/Functions/get-hero-img.js new file mode 100644 index 000000000..8ed1ac9b3 --- /dev/null +++ b/docs/src/components/Examples/Functions/get-hero-img.js @@ -0,0 +1,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) + } +} -- cgit v1.2.3