Skip to content

Commit a84f92c

Browse files
committed
mobile hamburger menu
1 parent 751de9e commit a84f92c

File tree

1 file changed

+43
-15
lines changed

1 file changed

+43
-15
lines changed

internal/website/_layouts/default.html

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,37 +39,42 @@
3939
.content { flex:1; min-width:0; padding:2rem 2.5rem; }
4040
.content .markdown-body { max-width: 100%; }
4141
pre, code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; }
42-
pre { background:#f6f8fa; border:1px solid #d0d7de; padding:.9rem 1rem; border-radius:6px; overflow:auto; }
43-
table { border-collapse:collapse; width:100%; }
42+
pre { background:#f6f8fa; border:1px solid #d0d7de; padding:.9rem 1rem; border-radius:6px; overflow-x:auto; max-width:100%; }
43+
code { word-wrap: break-word; }
44+
pre code { word-wrap: normal; }
45+
table { border-collapse:collapse; width:100%; overflow-x:auto; display:block; }
4446
th, td { border:1px solid #d0d7de; padding:.5rem .6rem; text-align:left; }
4547
th { background:#f2f5f8; }
4648
img { max-width:100%; height:auto; }
4749
footer { max-width:1400px; margin:0 auto; padding:2rem 1.5rem; border-top:1px solid var(--border); font-size:.8rem; color:#555; }
50+
.menu-toggle { display:none; background:#0366d6; color:#fff; border:none; padding:.5rem .75rem; border-radius:4px; cursor:pointer; font-size:.85rem; margin-left:auto; }
51+
.sidebar-overlay { display:none; position:fixed; inset:0; background:rgba(0,0,0,0.5); z-index:25; }
52+
.sidebar-overlay.active { display:block; }
4853
@media (max-width: 900px) {
4954
header { padding:.5rem 1rem; }
5055
header nav a { margin-left:.5rem; font-size:.85rem; }
5156
.logo-link { font-size:1.1rem !important; }
5257
.logo-link img { height:28px; }
53-
.layout { flex-direction:column; padding:0 .75rem 2rem; }
54-
.sidebar { position:relative; top:0; max-height:none; width:100%; border-right:none; border-bottom:1px solid var(--border); padding:.75rem .5rem; }
55-
.sidebar h4 { font-size:.7rem; margin:.8rem 0 .4rem; }
56-
.sidebar ul { margin-bottom:.5rem; }
57-
.sidebar li { margin:.25rem 0; }
58-
.sidebar a { padding:.2rem .3rem; font-size:.85rem; }
59-
.content { padding:1rem .75rem; }
60-
.content h1 { font-size:1.75rem; }
58+
.menu-toggle { display:block; }
59+
.layout { padding:0; }
60+
.sidebar { position:fixed; left:-100%; top:60px; bottom:0; width:280px; max-width:85vw; background:var(--bg); border-right:1px solid var(--border); border-bottom:none; z-index:30; transition:left 0.3s ease; overflow-y:auto; padding:1rem; }
61+
.sidebar.active { left:0; }
62+
.content { width:100%; padding:1.5rem 1rem; }
63+
.content h1 { font-size:1.75rem; margin-top:0; }
6164
.content h2 { font-size:1.4rem; }
6265
.content h3 { font-size:1.15rem; }
63-
pre { padding:.6rem .7rem; font-size:.85rem; overflow-x:auto; }
64-
table { font-size:.85rem; overflow-x:auto; display:block; }
66+
pre { padding:.6rem; font-size:.8rem; overflow-x:auto; white-space:pre; }
67+
table { font-size:.85rem; }
6568
footer { padding:1.5rem 1rem; font-size:.75rem; }
6669
}
6770
@media (max-width: 480px) {
68-
header nav a { font-size:.8rem; margin-left:.4rem; }
71+
header nav a { font-size:.75rem; margin-left:.4rem; }
6972
.logo-link span { font-size:1rem !important; }
70-
.content { padding:.75rem .5rem; }
73+
.content { padding:1rem .75rem; }
7174
.content h1 { font-size:1.5rem; }
72-
pre { font-size:.8rem; }
75+
.content h2 { font-size:1.25rem; }
76+
pre { font-size:.75rem; padding:.5rem; }
77+
.sidebar { width:100%; max-width:100%; }
7378
}
7479
</style>
7580
</head>
@@ -79,13 +84,15 @@
7984
<img src="/images/logo.png" alt="Go Micro Logo">
8085
<span style="font-size: 1.3rem; font-weight: bold; color: #222;">Go Micro</span>
8186
</a>
87+
<button class="menu-toggle" id="menuToggle">☰ Menu</button>
8288
<nav>
8389
<a href="/docs/">Docs</a>
8490
<a href="/docs/search.html">Search</a>
8591
<a href="https://github.com/micro/go-micro" target="_blank" rel="noopener">GitHub</a>
8692
<a href="/">Home</a>
8793
</nav>
8894
</header>
95+
<div class="sidebar-overlay" id="sidebarOverlay"></div>
8996
<div class="layout">
9097
<aside class="sidebar">
9198
{% assign nav = site.data.navigation %}
@@ -164,6 +171,27 @@ <h4>{{ section[0] | capitalize }}</h4>
164171
apply();
165172
});
166173
}
174+
// Mobile menu toggle
175+
const menuToggle = document.getElementById('menuToggle');
176+
const sidebar = document.querySelector('.sidebar');
177+
const overlay = document.getElementById('sidebarOverlay');
178+
if(menuToggle && sidebar && overlay){
179+
menuToggle.addEventListener('click', function(){
180+
sidebar.classList.toggle('active');
181+
overlay.classList.toggle('active');
182+
});
183+
overlay.addEventListener('click', function(){
184+
sidebar.classList.remove('active');
185+
overlay.classList.remove('active');
186+
});
187+
// Close sidebar when clicking a link
188+
sidebar.querySelectorAll('a').forEach(function(link){
189+
link.addEventListener('click', function(){
190+
sidebar.classList.remove('active');
191+
overlay.classList.remove('active');
192+
});
193+
});
194+
}
167195
})();
168196
</script>
169197
</body>

0 commit comments

Comments
 (0)