|
| 1 | +<script setup lang="ts"> |
| 2 | +import { onMounted, ref } from "vue"; |
| 3 | +import { withBase } from "vitepress"; |
| 4 | +
|
| 5 | +type HeroImage = { |
| 6 | + src: string; |
| 7 | + alt: string; |
| 8 | +}; |
| 9 | +
|
| 10 | +const HERO_IMAGES: HeroImage[] = [ |
| 11 | + { src: "/robotcode-toy-tray.png", alt: "RobotCode figurines on a tray" }, |
| 12 | + { src: "/robotcode-vintage.png", alt: "Vintage RobotCode poster" }, |
| 13 | + { src: "/robotcode-vintage-new.png", alt: "New vintage RobotCode artwork" }, |
| 14 | + { src: "/robotcode-golf.png", alt: "RobotCode playing golf" }, |
| 15 | + { src: "/robotcode-golf.png", alt: "RobotCode playing golf" }, |
| 16 | + { src: "/robotcode-rock.png", alt: "RobotCode playing rock music" }, |
| 17 | + { src: "/robotcode-soccer.png", alt: "RobotCode playing soccer" }, |
| 18 | + // { src: "/robotcode-vintage-christmas.png", alt: "Festive RobotCode postcard" }, |
| 19 | +]; |
| 20 | +
|
| 21 | +const hero = ref<HeroImage>(HERO_IMAGES[0]); |
| 22 | +
|
| 23 | +const pickRandomHero = () => { |
| 24 | + if (HERO_IMAGES.length <= 1) { |
| 25 | + return; |
| 26 | + } |
| 27 | + const index = Math.floor(Math.random() * HERO_IMAGES.length); |
| 28 | + hero.value = HERO_IMAGES[index]; |
| 29 | +}; |
| 30 | +
|
| 31 | +onMounted(() => { |
| 32 | + pickRandomHero(); |
| 33 | +}); |
| 34 | +</script> |
| 35 | + |
| 36 | +<template> |
| 37 | + <div class="random-hero"> |
| 38 | + <img class="VPImage image-src" :src="withBase(hero.src)" :alt="hero.alt" loading="eager" decoding="async" /> |
| 39 | + </div> |
| 40 | +</template> |
| 41 | + |
| 42 | +<style scoped> |
| 43 | +.random-hero { |
| 44 | + display: flex; |
| 45 | + justify-content: center; |
| 46 | + width: 100%; |
| 47 | +} |
| 48 | +
|
| 49 | +.image-src { |
| 50 | + width: auto; |
| 51 | + height: auto; |
| 52 | + max-width: 100%; |
| 53 | +} |
| 54 | +</style> |
0 commit comments