Repository navigation
Expand file tree
/
Copy pathHeader.astro
More file actions
134 lines (122 loc) · 5.44 KB
/
Copy pathHeader.astro
File metadata and controls
134 lines (122 loc) · 5.44 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
---
interface Props {
currentPath?: string;
}
const { currentPath = Astro.url.pathname } = Astro.props;
const navLinks = [
{ href: '/', label: 'Home' },
{ href: '/blog/', label: 'Blog' },
{ href: '/beyondthecode/', label: 'Beyond the Code' },
{ href: '/notes/', label: 'Notes' },
{ href: '/writing/', label: 'Writing' },
{ href: '/reading-list/', label: 'Reading' },
{ href: '/videos/', label: 'Videos' },
{ href: '/about/', label: 'About' },
];
function isActive(href: string): boolean {
if (href === '/') return currentPath === '/';
return currentPath.startsWith(href);
}
---
<header class="sticky top-0 z-50 w-full border-b border-[var(--border)] bg-[var(--background)]/95 backdrop-blur supports-[backdrop-filter]:bg-[var(--background)]/60">
<nav class="mx-auto flex h-14 max-w-6xl items-center justify-between px-4 sm:px-6 lg:px-8">
<!-- Logo -->
<a href="/" class="flex items-center gap-2 text-[var(--foreground)] hover:text-[var(--accent)] transition-colors group">
<svg width="28" height="28" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg" class="transition-transform group-hover:scale-105">
<rect x="2" y="4" width="28" height="24" rx="4" stroke="currentColor" stroke-width="1.5" fill="var(--background-secondary)" class="transition-colors"/>
<circle cx="6" cy="8" r="1.5" fill="#ef4444"/>
<circle cx="11" cy="8" r="1.5" fill="#eab308"/>
<circle cx="16" cy="8" r="1.5" fill="#10b981"/>
<path d="M6 16L10 20L6 24" stroke="#10b981" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<rect x="14" y="19" width="10" height="2" rx="1" fill="currentColor"/>
</svg>
<span class="text-xl font-semibold tracking-tight">rockoder</span>
</a>
<!-- Desktop Navigation -->
<div class="hidden md:flex items-center gap-6">
{navLinks.map((link) => (
<a
href={link.href}
class:list={[
'relative text-sm font-medium transition-colors py-1',
isActive(link.href)
? 'text-[var(--foreground)]'
: 'text-[var(--foreground-muted)] hover:text-[var(--foreground)]',
]}
>
{link.label}
{isActive(link.href) && (
<span class="absolute bottom-0 left-0 right-0 h-0.5 bg-[var(--accent)] rounded-full" />
)}
</a>
))}
<!-- Search trigger -->
<button
id="search-trigger"
class="flex items-center gap-2 rounded-lg border border-[var(--border)] bg-[var(--background-secondary)] px-3 py-1.5 text-sm text-[var(--foreground-muted)] hover:border-[var(--border-hover)] hover:text-[var(--foreground)] transition-colors"
aria-label="Open search"
>
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" />
</svg>
<span class="hidden lg:inline">Search</span>
<kbd class="hidden lg:inline-flex items-center gap-1 rounded bg-[var(--background)] px-1.5 text-xs text-[var(--foreground-subtle)]">
<span class="text-[10px]">⌘</span>K
</kbd>
</button>
</div>
<!-- Mobile menu button -->
<button
id="mobile-menu-button"
class="md:hidden flex items-center justify-center rounded-lg p-2 text-[var(--foreground-muted)] hover:bg-[var(--background-secondary)] hover:text-[var(--foreground)] transition-colors"
aria-label="Toggle menu"
aria-expanded="false"
>
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16" />
</svg>
</button>
</nav>
<!-- Mobile Navigation -->
<div id="mobile-menu" class="hidden md:hidden border-t border-[var(--border)]">
<nav class="mx-auto max-w-6xl px-4 py-4 sm:px-6 lg:px-8">
<div class="flex flex-col gap-1">
{navLinks.map((link) => (
<a
href={link.href}
class:list={[
'text-base font-medium transition-colors py-2 px-3 rounded-lg',
isActive(link.href)
? 'text-[var(--foreground)] bg-[var(--background-secondary)] border-l-2 border-[var(--accent)]'
: 'text-[var(--foreground-muted)] hover:text-[var(--foreground)] hover:bg-[var(--background-secondary)]',
]}
>
{link.label}
</a>
))}
</div>
</nav>
</div>
</header>
<script>
// Mobile menu toggle
const mobileMenuButton = document.getElementById('mobile-menu-button');
const mobileMenu = document.getElementById('mobile-menu');
mobileMenuButton?.addEventListener('click', () => {
const isExpanded = mobileMenuButton.getAttribute('aria-expanded') === 'true';
mobileMenuButton.setAttribute('aria-expanded', String(!isExpanded));
mobileMenu?.classList.toggle('hidden');
});
// Search trigger
const searchTrigger = document.getElementById('search-trigger');
searchTrigger?.addEventListener('click', () => {
document.dispatchEvent(new CustomEvent('open-search'));
});
// Keyboard shortcut for search
document.addEventListener('keydown', (e) => {
if ((e.metaKey || e.ctrlKey) && e.key === 'k') {
e.preventDefault();
document.dispatchEvent(new CustomEvent('open-search'));
}
});
</script>