|
| 1 | +<script setup lang="ts"> |
| 2 | +import { ACTIVE_NOODLES, PERMANENT_NOODLES, type Noodle } from '../Noodle' |
| 3 | +
|
| 4 | +const { env } = useAppConfig().buildInfo |
| 5 | +
|
| 6 | +const activeNoodlesData = ACTIVE_NOODLES.map(noodle => ({ |
| 7 | + key: noodle.key, |
| 8 | + date: noodle.date, |
| 9 | + timezone: noodle.timezone, |
| 10 | + tagline: noodle.tagline, |
| 11 | +})) |
| 12 | +
|
| 13 | +const permanentNoodlesData = PERMANENT_NOODLES.map(noodle => ({ |
| 14 | + key: noodle.key, |
| 15 | + tagline: noodle.tagline, |
| 16 | +})) |
| 17 | +
|
| 18 | +onPrehydrate(el => { |
| 19 | + const tagline = el.querySelector<HTMLElement>('#intro-header-tagline') |
| 20 | + const defaultLogo = el.querySelector<HTMLElement>('#intro-header-noodle-default') |
| 21 | +
|
| 22 | + if (!tagline || !defaultLogo) return |
| 23 | +
|
| 24 | + let permanentNoodles |
| 25 | + try { |
| 26 | + permanentNoodles = JSON.parse(el.dataset.permanentNoodles as string) as Noodle[] |
| 27 | + } catch { |
| 28 | + return |
| 29 | + } |
| 30 | + const activePermanentNoodle = permanentNoodles?.find(noodle => |
| 31 | + new URLSearchParams(window.location.search).has(noodle.key), |
| 32 | + ) |
| 33 | +
|
| 34 | + if (activePermanentNoodle) { |
| 35 | + const permanentNoodleLogo = el.querySelector<HTMLElement>( |
| 36 | + `#intro-header-noodle-${activePermanentNoodle.key}`, |
| 37 | + ) |
| 38 | +
|
| 39 | + if (!permanentNoodleLogo) return |
| 40 | +
|
| 41 | + permanentNoodleLogo.style.display = 'block' |
| 42 | + defaultLogo.style.display = 'none' |
| 43 | + if (activePermanentNoodle.tagline === false) { |
| 44 | + tagline.style.display = 'none' |
| 45 | + } |
| 46 | + return |
| 47 | + } |
| 48 | +
|
| 49 | + let activeNoodles |
| 50 | + try { |
| 51 | + activeNoodles = JSON.parse(el.dataset.activeNoodles as string) as Noodle[] |
| 52 | + } catch { |
| 53 | + return |
| 54 | + } |
| 55 | +
|
| 56 | + const currentActiveNoodles = activeNoodles.filter(noodle => { |
| 57 | + const todayDate = new Intl.DateTimeFormat('en-US', { |
| 58 | + timeZone: noodle.timezone === 'auto' ? undefined : noodle.timezone, |
| 59 | + month: '2-digit', |
| 60 | + day: '2-digit', |
| 61 | + year: 'numeric', |
| 62 | + }).format(new Date()) |
| 63 | +
|
| 64 | + const noodleDate = |
| 65 | + noodle.date && |
| 66 | + new Intl.DateTimeFormat('en-US', { |
| 67 | + timeZone: noodle.timezone === 'auto' ? undefined : noodle.timezone, |
| 68 | + month: '2-digit', |
| 69 | + day: '2-digit', |
| 70 | + year: 'numeric', |
| 71 | + }).format(new Date(noodle.date)) |
| 72 | + return todayDate === noodleDate |
| 73 | + }) |
| 74 | +
|
| 75 | + if (!currentActiveNoodles.length) return |
| 76 | +
|
| 77 | + const roll = Math.floor(Math.random() * currentActiveNoodles.length) |
| 78 | + const selectedNoodle = currentActiveNoodles[roll] |
| 79 | +
|
| 80 | + if (!selectedNoodle) return |
| 81 | +
|
| 82 | + const noodleLogo = el.querySelector<HTMLElement>(`#intro-header-noodle-${selectedNoodle.key}`) |
| 83 | +
|
| 84 | + if (!defaultLogo || !noodleLogo || !tagline) return |
| 85 | +
|
| 86 | + defaultLogo.style.display = 'none' |
| 87 | + noodleLogo.style.display = 'block' |
| 88 | + if (selectedNoodle.tagline === false) { |
| 89 | + tagline.style.display = 'none' |
| 90 | + } |
| 91 | +}) |
| 92 | +</script> |
| 93 | + |
| 94 | +<template> |
| 95 | + <div |
| 96 | + :data-active-noodles="JSON.stringify(activeNoodlesData)" |
| 97 | + :data-permanent-noodles="JSON.stringify(permanentNoodlesData)" |
| 98 | + > |
| 99 | + <h1 class="sr-only"> |
| 100 | + {{ $t('alt_logo') }} |
| 101 | + </h1> |
| 102 | + <div |
| 103 | + id="intro-header-noodle-default" |
| 104 | + class="relative mb-6 w-fit mx-auto motion-safe:animate-fade-in motion-safe:animate-fill-both" |
| 105 | + aria-hidden="true" |
| 106 | + > |
| 107 | + <AppLogo id="npmx-index-h1-logo-normal" class="w-42 h-auto sm:w-58 md:w-70" /> |
| 108 | + <span |
| 109 | + id="npmx-index-h1-logo-env" |
| 110 | + class="text-sm sm:text-base md:text-lg transform-origin-br font-mono tracking-widest text-accent absolute -bottom-4 -inset-ie-1.5" |
| 111 | + > |
| 112 | + {{ env === 'release' ? 'alpha' : env }} |
| 113 | + </span> |
| 114 | + </div> |
| 115 | + <component |
| 116 | + v-for="noodle in PERMANENT_NOODLES" |
| 117 | + :key="noodle.key" |
| 118 | + :id="`intro-header-noodle-${noodle.key}`" |
| 119 | + class="hidden" |
| 120 | + aria-hidden="true" |
| 121 | + :is="noodle.logo" |
| 122 | + /> |
| 123 | + <component |
| 124 | + v-for="noodle in ACTIVE_NOODLES" |
| 125 | + :key="noodle.key" |
| 126 | + :id="`intro-header-noodle-${noodle.key}`" |
| 127 | + class="hidden" |
| 128 | + aria-hidden="true" |
| 129 | + :is="noodle.logo" |
| 130 | + /> |
| 131 | + <p |
| 132 | + id="intro-header-tagline" |
| 133 | + class="text-fg-muted text-lg sm:text-xl max-w-xl mb-12 lg:mb-14 motion-safe:animate-slide-up motion-safe:animate-fill-both delay-100" |
| 134 | + > |
| 135 | + {{ $t('tagline') }} |
| 136 | + </p> |
| 137 | + </div> |
| 138 | +</template> |
0 commit comments