Add experimental icons support in menus, move icons to assets folder

This commit is contained in:
Alex Shpak
2025-09-22 23:47:25 +02:00
parent 69fb3210e8
commit 6ba59e191d
23 changed files with 79 additions and 63 deletions
+4
View File
@@ -222,6 +222,10 @@ bookSearchExclude = false
# (Optional) Set explicit href attribute for this page in a menu. # (Optional) Set explicit href attribute for this page in a menu.
bookHref = '' bookHref = ''
# /!\ This is an experimental feature, might be removed or changed at any time
# (Optional) Set an icon for the menu entity of the page, icons are discovered from `assets/icons` folder.
bookIcon = 'calendar'
``` ```
### Partials ### Partials
View File
+29 -36
View File
@@ -26,17 +26,20 @@ h6 {
} }
a { a {
display: inline-flex;
flex: auto;
align-items: center;
gap: .5em;
text-decoration: none; text-decoration: none;
cursor: default;
&[href] { &[href], &[role=button] {
color: var(--color-link); color: var(--color-link);
cursor: pointer;
} }
} }
img {
vertical-align: baseline;
}
small { small {
@extend .text-small; @extend .text-small;
} }
@@ -54,17 +57,17 @@ nav ul {
position: relative; position: relative;
} }
a, span { a {
padding: .5em 0; padding: .5em 0;
display: block; display: flex;
} }
a:hover { a[href]:hover, a[role=button]:hover {
opacity: 0.5; opacity: 0.5;
} }
ul { ul {
padding-inline-start: $padding-16; padding-inline-start: 1.5em;
} }
} }
@@ -116,10 +119,8 @@ a .book-icon {
@include fixed; @include fixed;
} }
a, a, label {
label {
color: inherit; color: inherit;
cursor: pointer;
word-wrap: break-word; word-wrap: break-word;
} }
@@ -127,22 +128,28 @@ a .book-icon {
color: var(--color-link); color: var(--color-link);
} }
input.toggle + label + ul { label > img:last-child {
display: none; height: 1em;
} width: 1em;
input.toggle:checked + label + ul { cursor: pointer;
display: block;
}
input.toggle + label::after {
content: "";
align-self: center; align-self: center;
transition: transform 0.1s ease-in-out; transition: transform 0.1s ease-in-out;
} }
input.toggle:checked + label::after { input.toggle + label + ul {
transform: rotate(90deg); display: none;
}
input.toggle:checked + label{
> img:last-child {
transform: rotate(90deg);
}
+ ul {
display: block;
}
} }
} }
@@ -214,11 +221,6 @@ body[dir="rtl"] .book-menu {
text-overflow: ellipsis; text-overflow: ellipsis;
margin: 0 $padding-16; margin: 0 $padding-16;
} }
img.book-icon {
height: 1.5em;
width: 1.5em;
}
} }
.book-layout-landing .book-header { .book-layout-landing .book-header {
@@ -322,11 +324,6 @@ body[dir="rtl"] .book-menu {
margin: $padding-4 0; margin: $padding-4 0;
padding: $padding-4 0; padding: $padding-4 0;
} }
a.flex {
display: inline-flex;
gap: $padding-8;
}
} }
.book-comments { .book-comments {
@@ -347,10 +344,6 @@ body[dir="rtl"] .book-menu {
ul { ul {
padding-inline-start: 1.5em; padding-inline-start: 1.5em;
} }
a.flex {
gap: 0.5em;
}
} }
// Responsive styles // Responsive styles
+1 -1
View File
@@ -180,7 +180,7 @@
list-style: none; list-style: none;
&::before { &::before {
content: ""; content: "";
display: inline-block; display: inline-block;
margin-inline-end: $padding-8; margin-inline-end: $padding-8;
transition: transform 0.1s ease-in-out; transition: transform 0.1s ease-in-out;
+1
View File
@@ -5,6 +5,7 @@
@import "normalize"; @import "normalize";
@import "utils"; @import "utils";
@import "main"; @import "main";
@import "fonts";
@import "print"; @import "print";
@import "markdown"; @import "markdown";

Before

Width:  |  Height:  |  Size: 347 B

After

Width:  |  Height:  |  Size: 347 B

Before

Width:  |  Height:  |  Size: 411 B

After

Width:  |  Height:  |  Size: 411 B

+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#1f1f1f"><path d="M504-480 320-664l56-56 240 240-240 240-56-56 184-184Z"/></svg>

After

Width:  |  Height:  |  Size: 178 B

Before

Width:  |  Height:  |  Size: 659 B

After

Width:  |  Height:  |  Size: 659 B

Before

Width:  |  Height:  |  Size: 349 B

After

Width:  |  Height:  |  Size: 349 B

Before

Width:  |  Height:  |  Size: 451 B

After

Width:  |  Height:  |  Size: 451 B

Before

Width:  |  Height:  |  Size: 753 B

After

Width:  |  Height:  |  Size: 753 B

Before

Width:  |  Height:  |  Size: 650 B

After

Width:  |  Height:  |  Size: 650 B

+2 -2
View File
@@ -4,7 +4,7 @@
{{ if and .GitInfo .Site.Params.BookLastChangeLink }} {{ if and .GitInfo .Site.Params.BookLastChangeLink }}
{{- $date := partial "docs/date" (dict "Date" .Lastmod "Format" .Site.Params.BookDateFormat) -}} {{- $date := partial "docs/date" (dict "Date" .Lastmod "Format" .Site.Params.BookDateFormat) -}}
<a class="flex align-center" href="{{ partial "docs/links/commit" . }}" title='{{ i18n "Last modified by" }} {{ .GitInfo.AuthorName }} | {{ $date }}' target="_blank" rel="noopener"> <a class="flex align-center" href="{{ partial "docs/links/commit" . }}" title='{{ i18n "Last modified by" }} {{ .GitInfo.AuthorName }} | {{ $date }}' target="_blank" rel="noopener">
<img src="{{ "svg/calendar.svg" | relURL }}" class="book-icon" alt="" /> <img src="{{ partial "docs/icon" "calendar" }}" class="book-icon" alt="" />
<span>{{ $date }}</span> <span>{{ $date }}</span>
</a> </a>
{{ end }} {{ end }}
@@ -13,7 +13,7 @@
<div> <div>
{{ if and .File .Site.Params.BookEditLink }} {{ if and .File .Site.Params.BookEditLink }}
<a class="flex align-center" href="{{ partial "docs/links/edit" . }}" target="_blank" rel="noopener edit"> <a class="flex align-center" href="{{ partial "docs/links/edit" . }}" target="_blank" rel="noopener edit">
<img src="{{ "svg/edit.svg" | relURL }}" class="book-icon" alt="" /> <img src="{{ partial "docs/icon" "edit" }}" class="book-icon" alt="" />
<span>{{ i18n "Edit this page" }}</span> <span>{{ i18n "Edit this page" }}</span>
</a> </a>
{{ end }} {{ end }}
+2 -2
View File
@@ -1,13 +1,13 @@
<div class="flex align-center justify-between"> <div class="flex align-center justify-between">
<label for="menu-control"> <label for="menu-control">
<img src="{{ "svg/menu.svg" | relURL }}" class="book-icon" alt="Menu" /> <img src="{{ partial "docs/icon" "menu" }}" class="book-icon" alt="Menu" />
</label> </label>
<h3>{{ partial "docs/title" . }}</h3> <h3>{{ partial "docs/title" . }}</h3>
<label for="toc-control"> <label for="toc-control">
{{ if partial "docs/toc-show" . }} {{ if partial "docs/toc-show" . }}
<img src="{{ "svg/toc.svg" | relURL }}" class="book-icon" alt="Table of Contents" /> <img src="{{ partial "docs/icon" "toc" }}" class="book-icon" alt="Table of Contents" />
{{ end }} {{ end }}
</label> </label>
</div> </div>
+3
View File
@@ -0,0 +1,3 @@
{{- with resources.Get (printf "icons/%s.svg" .) -}}
{{- .RelPermalink -}}
{{- end -}}
+6 -5
View File
@@ -14,17 +14,18 @@
<li> <li>
<input type="checkbox" id="languages" class="toggle" /> <input type="checkbox" id="languages" class="toggle" />
<label for="languages" class="flex"> <label for="languages" class="flex">
<a role="button" class="flex flex-auto"> <a role="button">
<img src="{{ "svg/translate.svg" | relURL }}" class="book-icon" alt="Languages" /> <img src="{{ partial "docs/icon" "translate" }}" class="book-icon" alt="Languages" />
<span>{{ $.Site.Language.LanguageName }}</span> {{ $.Site.Language.LanguageName }}
</a> </a>
<img src="{{ partial "docs/icon" "chevron-right" }}" class="book-icon" />
</label> </label>
<ul> <ul>
{{ range .Site.Languages }}{{ with index $translations .Lang }} {{ range .Site.Languages }}{{ with index $translations .Lang }}
<li> <li>
<a href="{{ cond hugo.IsMultihost .Permalink .RelPermalink }}"> <a href="{{ cond hugo.IsMultihost .Permalink .RelPermalink }}" class="flex flex-auto">
<span>{{ .Language.LanguageName }}</span> {{ .Language.LanguageName }}
</a> </a>
</li> </li>
{{ end }}{{ end }} {{ end }}{{ end }}
+15 -5
View File
@@ -31,19 +31,29 @@
{{ if .Page.Params.BookCollapseSection }} {{ if .Page.Params.BookCollapseSection }}
<input type="checkbox" id="section-{{ md5 .Page }}" class="toggle" {{ if or $current $ancestor }}checked{{ end }} /> <input type="checkbox" id="section-{{ md5 .Page }}" class="toggle" {{ if or $current $ancestor }}checked{{ end }} />
<label for="section-{{ md5 .Page }}" class="flex"> <label for="section-{{ md5 .Page }}" class="flex">
<a {{ if .Page.Content }}href="{{ .Page.RelPermalink }}"{{ else }}role="button"{{ end }} class="flex-auto {{ if $current }}active{{ end }}"> <a {{ if .Page.Content }}href="{{ .Page.RelPermalink }}"{{ else }}role="button"{{ end }} class="{{ if $current }}active{{ end }}">
{{- partial "docs/title" .Page -}} {{ template "book-icon-title" .Page -}}
</a> </a>
<img src="{{ partial "docs/icon" "chevron-right" }}" class="book-icon" />
</label> </label>
{{ else if .Page.Params.BookHref }} {{ else if .Page.Params.BookHref }}
<a href="{{ .Page.Params.BookHref }}" class="{{ if $current }}active{{ end }}" target="_blank" rel="noopener"> <a href="{{ .Page.Params.BookHref }}" class="{{ if $current }}active{{ end }}" target="_blank" rel="noopener">
{{- partial "docs/title" .Page -}} {{ template "book-icon-title" .Page -}}
</a> </a>
{{ else if .Page.Content }} {{ else if .Page.Content }}
<a href="{{ .Page.RelPermalink }}" class="{{ if $current }}active{{ end }}"> <a href="{{ .Page.RelPermalink }}" class="{{ if $current }}active{{ end }}">
{{- partial "docs/title" .Page -}} {{ template "book-icon-title" .Page -}}
</a> </a>
{{ else }} {{ else }}
<span>{{- partial "docs/title" .Page -}}</span> <a>
{{ template "book-icon-title" .Page -}}
</a>
{{ end }} {{ end }}
{{ end }} {{ end }}
{{ define "book-icon-title" }}
{{- with .Page.Params.BookIcon -}}
<img src="{{ partial "docs/icon" . }}" class="book-icon" />
{{- end -}}
{{- partial "docs/title" .Page -}}
{{ end }}
+8 -5
View File
@@ -35,9 +35,12 @@
{{ end }} {{ end }}
{{ define "book-menu-title" }} {{ define "book-menu-title" }}
{{ if .Name }} {{- with .Params.BookIcon -}}
{{ .Name }} <img src="{{ partial "docs/icon" . }}" class="book-icon" />
{{ else if .Page }} {{- end -}}
{{ partial "docs/title" .Page }} {{- if .Name -}}
{{ end }} {{- .Name -}}
{{- else if .Page -}}
{{- partial "docs/title" .Page -}}
{{- end -}}
{{ end }} {{ end }}
+2 -2
View File
@@ -3,7 +3,7 @@
<span> <span>
{{- with .Paginator.Prev }} {{- with .Paginator.Prev }}
<a href="{{ .URL }}" class="flex align-center"> <a href="{{ .URL }}" class="flex align-center">
<img src="{{ "svg/backward.svg" | relURL }}" class="book-icon" alt="Previous" /> <img src="{{ partial "docs/icon" "backward" }}" class="book-icon" alt="Previous" />
</a> </a>
{{ end }} {{ end }}
</span> </span>
@@ -20,7 +20,7 @@
<span> <span>
{{- with .Paginator.Next }} {{- with .Paginator.Next }}
<a href="{{ .URL }}" class="flex align-center"> <a href="{{ .URL }}" class="flex align-center">
<img src="{{ "svg/forward.svg" | relURL }}" class="book-icon" alt="Next" /> <img src="{{ partial "docs/icon" "forward" }}" class="book-icon" alt="Next" />
</a> </a>
{{ end }} {{ end }}
</span> </span>
+1 -1
View File
@@ -1,6 +1,6 @@
{{ with .Date }} {{ with .Date }}
<div class="flex align-center text-small book-post-date"> <div class="flex align-center text-small book-post-date">
<img src="{{ "svg/calendar.svg" | relURL }}" class="book-icon" alt="" /> <img src="{{ partial "docs/icon" "calendar" }}" class="book-icon" alt="" />
<span>{{ partial "docs/date" (dict "Date" . "Format" $.Site.Params.BookDateFormat) }}</span> <span>{{ partial "docs/date" (dict "Date" . "Format" $.Site.Params.BookDateFormat) }}</span>
</div> </div>
{{ end }} {{ end }}
+2 -2
View File
@@ -2,7 +2,7 @@
<div> <div>
{{ with .NextInSection }} {{ with .NextInSection }}
<a href="{{ .RelPermalink }}" class="flex align-center"> <a href="{{ .RelPermalink }}" class="flex align-center">
<img src="{{ "svg/backward.svg" | relURL }}" class="book-icon" alt="Previous" title="{{ partial "docs/title" . }}" /> <img src="{{ partial "docs/icon" "backward" }}" class="book-icon" alt="Previous" title="{{ partial "docs/title" . }}" />
<span>{{ partial "docs/title" . }}</span> <span>{{ partial "docs/title" . }}</span>
</a> </a>
{{ end }} {{ end }}
@@ -11,7 +11,7 @@
{{ with .PrevInSection }} {{ with .PrevInSection }}
<a href="{{ .RelPermalink }}" class="flex align-center"> <a href="{{ .RelPermalink }}" class="flex align-center">
<span>{{ partial "docs/title" . }}</span> <span>{{ partial "docs/title" . }}</span>
<img src="{{ "svg/forward.svg" | relURL }}" class="book-icon" alt="Next" title="{{ partial "docs/title" . }}" /> <img src="{{ partial "docs/icon" "forward" }}" class="book-icon" alt="Next" title="{{ partial "docs/title" . }}" />
</a> </a>
{{ end }} {{ end }}
</div> </div>
+2 -2
View File
@@ -13,7 +13,7 @@
<span> <span>
{{ with $prev }} {{ with $prev }}
<a href="{{ .RelPermalink }}" class="flex align-center"> <a href="{{ .RelPermalink }}" class="flex align-center">
<img src="{{ "svg/backward.svg" | relURL }}" class="book-icon" alt="Previous" title="{{ partial "docs/title" . }}" /> <img src="{{ partial "docs/icon" "backward" }}" class="book-icon" alt="Previous" title="{{ partial "docs/title" . }}" />
<span>{{ partial "docs/title" . }}</span> <span>{{ partial "docs/title" . }}</span>
</a> </a>
{{ end }} {{ end }}
@@ -22,7 +22,7 @@
{{ with $next }} {{ with $next }}
<a href="{{ .RelPermalink }}" class="flex align-center"> <a href="{{ .RelPermalink }}" class="flex align-center">
<span>{{ partial "docs/title" . }}</span> <span>{{ partial "docs/title" . }}</span>
<img src="{{ "svg/forward.svg" | relURL }}" class="book-icon" alt="Next" title="{{ partial "docs/title" . }}" /> <img src="{{ partial "docs/icon" "forward" }}" class="book-icon" alt="Next" title="{{ partial "docs/title" . }}" />
</a> </a>
{{ end }} {{ end }}
</span> </span>