-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathapp.vue
160 lines (146 loc) · 4.12 KB
/
app.vue
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<script lang="ts" setup>
import { useSettings } from '~~/store/settings'
const colorMode = useColorMode()
const themeColor = computed(() => {
return colorMode.preference === 'dark' ? '#1e2124' : '#f1f5f9'
})
const i18nHead = useLocaleHead({
addDirAttribute: true,
identifierAttribute: 'id',
addSeoAttributes: true,
})
const url = useRequestURL()
const settings = useSettings()
const { getFavicon } = useAppConfig()
useHead({
htmlAttrs: {
lang: i18nHead.value.htmlAttrs?.lang,
dir: i18nHead.value.htmlAttrs?.dir,
},
noscript: [
{
children: 'JavaScript is required',
},
],
link: [
...(i18nHead.value.link || []),
{ rel: 'icon', type: 'image/x-icon', href: getFavicon(settings.group) },
{ rel: 'canonical', href: url.href },
{ rel: 'preconnect', href: 'https://fonts.googleapis.com' },
{
rel: 'preconnect',
href: 'https://fonts.gstatic.com',
crossorigin: 'anonymous',
},
],
meta: [
...(i18nHead.value.meta || []),
{ content: () => themeColor.value, name: 'theme-color' },
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
],
})
const { group } = useSettings()
const { getGroupTitle, getMetaImage } = useAppConfig()
const description = `A Fanmade Website for ${getGroupTitle(
group,
)} Showroom. Discover the latest ${getGroupTitle(
group,
)} member showroom live streams, member profile, and fans ranking!`
useSeoMeta({
title: `${getGroupTitle(group)} Showroom Log`,
ogTitle: () => `${getGroupTitle(group)} Showroom Log`,
description,
ogSiteName: `${getGroupTitle(group)} Showroom Log`,
ogDescription: description,
ogImage: getMetaImage(group),
twitterTitle: `${getGroupTitle(group)} Showroom Log`,
twitterDescription: description,
twitterImage: getMetaImage(group),
twitterCard: 'summary',
ogType: 'website',
})
// TODO: Remove when https://github.com/vuejs/core/issues/5513 fixed
const key = ref(0)
const messages = [
'Uncaught NotFoundError: Failed to execute \'insertBefore\' on \'Node\': The node before which the new node is to be inserted is not a child of this node.', // chromium based
'NotFoundError: The object can not be found here.', // safari
]
if (typeof window !== 'undefined') {
// @ts-expect-error using arbitrary window key
if (!window.__vue5513) {
window.addEventListener('error', (event) => {
if (messages.includes(event.message)) {
event.preventDefault()
console.warn(
'Rerendering layout because of https://github.com/vuejs/core/issues/5513',
)
key.value++
}
})
}
// @ts-expect-error using arbitrary window key
window.__vue5513 = true
}
// const { $pwa } = useNuxtApp()
const keys = useMagicKeys({
passive: false,
onEventFired(e) {
if (
e.code === 'Escape'
&& e.type === 'keydown'
&& document.activeElement?.id === 'search_shortcut'
) {
if ((document.activeElement as HTMLInputElement | null)?.value !== '') {
;(document.activeElement as HTMLInputElement).value = ''
;(document.activeElement as HTMLInputElement).blur()
}
}
else if (e.code === 'KeyK' && e.ctrlKey) {
e.preventDefault()
}
},
})
const shiftCtrlA = keys['Ctrl+K']
watch(shiftCtrlA, (v) => {
if (v) {
const input = document.querySelector(
'input#search_shortcut',
) as HTMLElement | null
input?.focus()
}
})
const navRect = useState<DOMRect | null>('navRect', () => null)
const navElement = ref<HTMLElement>()
onMounted(() => {
const el = document.querySelector('#navbar')
if (el) {
navElement.value = el as HTMLElement
navRect.value = el.getBoundingClientRect()
}
})
const { width } = useElementSize(navElement)
watch(width, () => {
navRect.value = navElement.value!.getBoundingClientRect()
})
// useCSRF()
useAuth()
</script>
<template>
<div>
<NuxtLoadingIndicator />
<Dialog />
<LiveUserDraggable />
<NotificationView />
<NuxtLayout>
<NuxtPage
:key="key"
:transition="{
name: 'page',
mode: 'out-in',
}"
/>
</NuxtLayout>
<!-- <NuxtPwaManifest /> -->
</div>
</template>