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