Skip to content

Commit c036f90

Browse files
committed
Theme: Expand at most one sidebar group for the current page
Among the sidebar groups that use block_expand=active, only expand one group for the "current" page. Example: On qunitjs.com, some pages cross-promoted in multiple groups for improved discovery. Such as "QUnit.config.current" which is primarily a config page, but also listed under "Extension interfaces". Instead of expanding both "Configuration" and "Ext interfaces", and thus pushing down the TOC even further and making navivation unclear, expand only the first match. When interested in exploring other pages in the same secondary group related to a page, one can still click the sidebar heading to expand it, and/or the category link atop the current page.
1 parent 33ed336 commit c036f90

File tree

5 files changed

+41
-3
lines changed

5 files changed

+41
-3
lines changed

_data/sidebar_api.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
- group: lorem
66

7+
- group: quux
8+
79
- group: deprecated
810
expand: false
911
title: Deprecated

_includes/sidebar.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,19 @@
4141
Whether a block should be expanded.
4242
- true: Always expanded.
4343
- false: Never expanded.
44-
- active: Expand when the current page is in the list.
44+
- active: Expand when the current page is in the list,
45+
unless another block has already been expanded for the current page.
46+
(If a page is in multiple categories, only expand the first and
47+
presumed most-important once. The others can be navigated by clicking
48+
on the category atop the page and/or in the sidebar instead.)
4549
- initial: Expand on the home page, and when the current page is in the list.
4650

4751
* initial: [Default: "/"]
4852
Override which address the "initial" expand mode will compare to.
4953

5054
{%- endcomment -%}
5155
<aside class="sidebar" role="complementary">
56+
{%- assign block_expand_active_once = false -%}
5257
{%- for block in site.data[include.blocks] -%}
5358
{%- assign block_type = block.type | default: "group" -%}
5459
{%- assign block_title = block.title -%}
@@ -94,8 +99,9 @@
9499

95100
{%- if block_expand == "active" -%}
96101
{%- assign self_in_contents = block_contents | where: 'url', page.url | size -%}
97-
{%- if page.url == block_url or self_in_contents > 0 -%}
102+
{%- if page.url == block_url or self_in_contents > 0 and block_expand_active_once == false -%}
98103
{%- assign block_expand = true -%}
104+
{%- assign block_expand_active_once = true -%}
99105
{%- else -%}
100106
{%- assign block_expand = false -%}
101107
{%- endif -%}

api/foo/quux.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ title: .quuz()
44
excerpt: Hello, where was I?
55
groups:
66
- foo
7+
- quux
78
---
89

9-
That's weird. So, where was I? Oh, that's right, Barcelona!
10+
New teeth. That's weird. So, where was I? Oh, that's right. Barcelona!
1011

1112
This entry has no version information.

api/lorem/quux.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
layout: page-api
3+
title: Example.quux()
4+
excerpt: Thanks for coming.
5+
groups:
6+
- lorem
7+
- quux
8+
version_added: "2.0.0"
9+
---
10+
11+
A quote from an funny scene:
12+
13+
> Hammond: Thank you for coming, Thor.<br>
14+
> Thor: It is my pleasure, General Hammond.
15+
>
16+
> []
17+
>
18+
> Kinsey: My name is - <br>
19+
> Thor: Senator Kinsey. O'Neill suggested I send you to a distant planet for your actions, but I am reasonably certain that his statement was in jest.<br>
20+
> Kinsey: I am sure it was, Commander - <br>
21+
> Thor: Supreme Commander.

api/quux/index.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
layout: group
3+
group: quux
4+
title: Special quux
5+
amethyst:
6+
toc: true
7+
---
8+

0 commit comments

Comments
 (0)