-
-
Notifications
You must be signed in to change notification settings - Fork 427
Expand file tree
/
Copy pathapp.vue
More file actions
65 lines (48 loc) · 1.46 KB
/
app.vue
File metadata and controls
65 lines (48 loc) · 1.46 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
<script setup lang="ts">
import { useEventListener } from '@vueuse/core'
const route = useRoute()
const router = useRouter()
// Initialize accent color before hydration to prevent flash
initAccentOnPrehydrate()
const isHomepage = computed(() => route.name === 'index')
useHead({
titleTemplate: titleChunk => {
return titleChunk ? titleChunk : 'npmx - Better npm Package Browser'
},
})
// Global keyboard shortcut: "/" focuses search or navigates to search page
function handleGlobalKeydown(e: KeyboardEvent) {
const target = e.target as HTMLElement
const isEditableTarget =
target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.isContentEditable
if (isEditableTarget) {
return
}
if (e.key === '/') {
e.preventDefault()
// Try to find and focus search input on current page
const searchInput = document.querySelector<HTMLInputElement>(
'input[type="search"], input[name="q"]',
)
if (searchInput) {
searchInput.focus()
return
}
router.push('/search')
}
}
if (import.meta.client) {
useEventListener(document, 'keydown', handleGlobalKeydown)
}
</script>
<template>
<div class="min-h-screen flex flex-col bg-bg text-fg">
<a href="#main-content" class="skip-link font-mono">Skip to main content</a>
<AppHeader :show-logo="!isHomepage" />
<div id="main-content" class="flex-1 flex flex-col">
<NuxtPage />
</div>
<AppFooter />
<ScrollToTop />
</div>
</template>