Skip to content

Commit 19cf3e8

Browse files
committed
harmonize sidebar
1 parent bfff5e0 commit 19cf3e8

File tree

3 files changed

+45
-25
lines changed

3 files changed

+45
-25
lines changed

assets/css/global.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,6 @@ input[type="search"]::-ms-clear {
104104
list-style-type: lower-roman;
105105
}
106106
}
107+
.navbar-group:first-of-type {
108+
margin-top: 0.2rem !important;
109+
}

assets/css/utilities.css

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,20 @@
118118
}
119119
}
120120

121+
@utility navbar-entry-margin {
122+
@apply px-2 py-1;
123+
}
124+
125+
@utility navbar-group {
126+
@apply mt-5;
127+
}
128+
129+
@utility navbar-entry-background-current {
130+
@apply bg-gray-100 dark:bg-gray-900;
131+
}
121132
@utility navbar-group-font-title {
122133
font-size: var(--color-navbar-group-font-title-size);
123-
@apply font-semibold uppercase;
134+
@apply pb-1.5 font-semibold uppercase;
124135
color: var(--color-navbar-text);
125136
.dark & {
126137
color: var(--color-navbar-text-dark);

layouts/partials/sidebar/sections.html

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,36 @@
3232
{{- end }}
3333
{{- range .Params.sidebar.groups }}
3434
<!-- Main titles -->
35-
<li class="navbar-group-font-title mt-2 px-2 py-2 pt-5 pb-2">
36-
{{ . }}
37-
</li>
38-
{{- range where $pages "Params.sidebar.group" . }}
39-
{{- if .IsSection }}
40-
{{- template "renderList" . }}
41-
{{- else }}
42-
{{- template "renderSingle" . }}
35+
<div class="navbar-group">
36+
<li class="navbar-group-font-title">
37+
{{ . }}
38+
</li>
39+
{{- range where $pages "Params.sidebar.group" . }}
40+
{{- if .IsSection }}
41+
{{- template "renderList" . }}
42+
{{- else }}
43+
{{- template "renderSingle" . }}
44+
{{- end }}
4345
{{- end }}
44-
{{- end }}
46+
</div>
4547
{{- end }}
48+
4649
{{ end }}
4750

4851
{{/* Recursive template for sidebar items */}}
4952
{{ define "renderList" }}
5053
{{ $isCurrent := eq page . }}
5154
{{ $expanded := or $isCurrent (page.IsDescendant .) }}
52-
<li x-data="{ expanded: {{ $expanded }} }">
55+
<li class="" x-data="{ expanded: {{ $expanded }} }">
5356
<div
54-
class="justify-between{{ if $isCurrent }}
55-
bg-gray-100 dark:bg-gray-900
56-
{{ end }} flex w-full items-center rounded-sm px-4"
57+
class="{{ if $isCurrent }}
58+
navbar-entry-background-current
59+
{{ end }} flex w-full items-center justify-between rounded-sm"
5760
>
58-
<div class="w-full truncate py-1">
61+
<div class="navbar-entry-margin w-full truncate">
5962
{{- if .Permalink }}
6063
{{/* If the link is not empty, use it */}}
64+
<!-- Sections that have children and linking to a page -->
6165
<a
6266
{{ if $isCurrent }}
6367
aria-current="page" id="sidebar-current-page"
@@ -69,6 +73,7 @@
6973
</a>
7074
{{- else }}
7175
{{/* Otherwise, just expand the section */}}
76+
<!-- Sections that have children and do not link to a page -->
7277
<button
7378
@click="expanded = !expanded"
7479
class="hover:text-blue w-full text-left select-none hover:dark:text-blue-400"
@@ -77,9 +82,10 @@
7782
</button>
7883
{{- end }}
7984
</div>
85+
<!-- Expand group button -->
8086
<button
8187
@click="expanded = !expanded"
82-
class="rounded-sm hover:bg-gray-300 hover:dark:bg-gray-300"
88+
class="rounded-sm hover:bg-gray-200 hover:dark:bg-gray-800"
8389
>
8490
<span
8591
:class="{ 'hidden' : expanded }"
@@ -106,9 +112,9 @@
106112

107113
{{ define "renderSingle" }}
108114
{{- if .Params.sidebar.goto }}
109-
<li class="hover:text-blue px-4 hover:dark:text-blue-400">
115+
<li class="navbar-entry-margin hover:text-blue hover:dark:text-blue-400">
110116
<a
111-
class="block w-full truncate py-2"
117+
class="block w-full truncate"
112118
href="{{ .Params.sidebar.goto }}"
113119
title="{{ .LinkTitle }}"
114120
>
@@ -118,15 +124,15 @@
118124
{{- else }}
119125
{{ $isCurrent := eq page . }}
120126
<li
121-
class="hover:text-blue {{ if $isCurrent }}
122-
bg-gray-100 dark:bg-gray-900
123-
{{ end }} rounded-sm px-4 hover:dark:text-blue-400"
127+
class="navbar-entry-margin hover:text-blue {{ if $isCurrent }}
128+
navbar-entry-background-current
129+
{{ end }} rounded-sm hover:dark:text-blue-400"
124130
>
125131
<a
126132
{{ if $isCurrent }}
127133
aria-current="page" id="sidebar-current-page"
128134
{{ end }}
129-
class="block w-full truncate py-2"
135+
class="block w-full truncate"
130136
href="{{ .Permalink }}"
131137
title="{{ .LinkTitle }}"
132138
>
@@ -139,8 +145,8 @@
139145
{{ define "renderTitle" }}
140146
{{ .LinkTitle }}
141147
{{- with .Params.sidebar.badge }}
142-
<span
143-
>{{- partial "components/badge.html" (dict "color" .color "content" .text) }}</span
144-
>
148+
<span>
149+
{{- partial "components/badge.html" (dict "color" .color "content" .text) }}
150+
</span>
145151
{{- end }}
146152
{{ end }}

0 commit comments

Comments
 (0)