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