Files
bridget/layouts/partials/nav.html
Spedon ae1a08eb82 feat: embed threshold and index val of navbar into html/inline js (#241)
* feat: refactor image retrieval logic and improve variable initialization

- Add a new file `layouts/partials/function/getImageSlice.html`
- Initialize variables `$context`, `$Path`, and `$params`
- Set `$Path` based on the result of the `partial/function/currentMenuItem.html` partial
- Retrieve the page `$gallery` based on `$Path`
- Return all resources of type `image` from `$gallery`

* refactor: adapt getImageSlice function to `single.json`

* feat: refactor navigation UI components to use static go template

* feat: update navigation functionality and threshold rendering
2024-01-20 18:03:26 +08:00

89 lines
2.3 KiB
HTML

<nav>
<div class="navArtist">
<a href="/">{{ site.Title }}</a>
</div>
<div class="links">
{{- $index := 0 -}}
{{- $currentIndex := -1 -}}
{{- with partial "function/currentMenuItem.html" . -}}
{{- $currentIndex = sub .Weight 1 -}}
{{- end -}}
{{- $menus := .Site.Menus.main -}}
{{- $len := len $menus }}
{{- range $menus -}}
{{- $url := .URL | relURL -}}
{{- if eq (add $index 1) $len -}}
<a
href="{{- .URL | relURL -}}"
class="link{{- if eq $index $currentIndex -}}
{{- printf " current" -}}
{{- end -}}"
>{{- .Title -}}</a
>
{{- else -}}
<a
href="{{- .URL | relURL -}}"
class="link{{- if eq $index $currentIndex -}}
{{- printf " current" -}}
{{- end -}}"
>{{- .Title -}}</a
>,&nbsp
{{- end -}}
{{- $index = add $index 1 -}}
{{- end -}}
</div>
<div class="threshold">
{{- $length := 0 -}}
{{- with partial "function/getImageSlice.html" . -}}
{{- $length = len . -}}
{{- end -}}
<span>{{- i18n "threshold" | strings.FirstUpper -}}:</span>
<span>
<button class="dec">&#xFF0D;</button>
<span class="num"></span><span class="num"></span><span class="num"></span
><span class="num"></span>
<button class="inc">&#xFF0B;</button>
</span>
</div>
<div class="index">
<span class="num">0</span><span class="num">0</span><span class="num">0</span
><span class="num">0</span>
<span>/</span>
<span class="num">{{- math.Floor (div $length 1000) -}}</span
><span class="num">{{- mod (math.Floor (div $length 100)) 10 -}}</span
><span class="num">{{- mod (math.Floor (div $length 10)) 10 -}}</span
><span class="num">{{- mod $length 10 -}}</span>
</div>
</nav>
{{- /* for threshold */ -}}
<script>
i = 2
const s = sessionStorage.getItem('thresholdsIndex')
if (s !== null) {
i = parseInt(s)
}
var t = ''
switch (i) {
case 0:
t = '0020'
break
case 1:
t = '0040'
break
case 2:
t = '0080'
break
case 3:
t = '0140'
break
case 4:
t = '0200'
break
}
Array.from(
document.getElementsByClassName('threshold').item(0).getElementsByClassName('num')
).forEach((e, i) => {
e.innerText = t[i]
})
</script>