diff options
author | Runxi Yu <me@runxiyu.org> | 2025-03-02 11:14:24 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-03-02 11:14:24 +0800 |
commit | a70083fb23ad51dde285d55b6792beab4021fc89 (patch) | |
tree | 52c33668b50c8b8858da782f640d5fc752bc6802 | |
parent | Fix nav state (diff) | |
download | website-a70083fb23ad51dde285d55b6792beab4021fc89.tar.gz website-a70083fb23ad51dde285d55b6792beab4021fc89.tar.zst website-a70083fb23ad51dde285d55b6792beab4021fc89.zip |
Recursive navigation
-rw-r--r-- | assets/style.css | 12 | ||||
-rw-r--r-- | layouts/_default/baseof.html | 22 | ||||
-rw-r--r-- | layouts/partials/recursive_nav.html | 12 |
3 files changed, 17 insertions, 29 deletions
diff --git a/assets/style.css b/assets/style.css index 0ac750e..bb7cbdc 100644 --- a/assets/style.css +++ b/assets/style.css @@ -50,17 +50,13 @@ aside#sidebar a:visited { color: var(--fg); } - -aside#sidebar > ul > li:not(first-child) { - margin-top: 1rem; -} - -aside#sidebar > ul { +aside#sidebar ul { list-style: none; + padding-left: 1rem; } -aside#sidebar ul { - padding-left: 1rem; +aside#sidebar > ul > li:not(first-child) { + margin-top: 1rem; } aside#sidebar > ul { diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 3fbc126..c6e0e3b 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -12,27 +12,7 @@ <p style="text-align: center; font-weight: bold;"> <a href="/">{{ .Site.Title }}</a> </p> - {{ $currentPage := . }} - <ul> - {{ range .Site.Sections }} - {{ if eq $currentPage . }} - <li class="nav-current"><a href="{{ .RelPermalink }}">{{ .Title }}</a></li> - {{ else }} - <li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li> - {{ end }} - {{ if or (eq $currentPage .) ($currentPage.IsDescendant .) }} - <ul> - {{ range .Pages }} - {{ if eq $currentPage . }} - <li class="nav-current"><a href="{{ .RelPermalink }}">{{ .Title }}</a></li> - {{ else }} - <li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li> - {{ end }} - {{ end }} - </ul> - {{ end }} - {{ end }} - </ul> + {{ partial "recursive_nav.html" (dict "currentPage" . "pages" .Site.Sections) }} </aside> <div id="main-and-footer"> <main> diff --git a/layouts/partials/recursive_nav.html b/layouts/partials/recursive_nav.html new file mode 100644 index 0000000..4a3ed2c --- /dev/null +++ b/layouts/partials/recursive_nav.html @@ -0,0 +1,12 @@ +{{ $currentPage := .currentPage }} +<ul> + {{ range .pages }} + {{ $isCurrentOrAncestor := or (eq $currentPage .) ($currentPage.IsDescendant .) }} + <li {{ if eq $currentPage . }}class="nav-current"{{ end }}> + <a href="{{ .RelPermalink }}">{{ .Title }}</a> + </li> + {{ if and .Pages $isCurrentOrAncestor }} + {{ partial "recursive_nav.html" (dict "currentPage" $currentPage "pages" .Pages) }} + {{ end }} + {{ end }} +</ul> |