Skip to content

Commit 45e5a51

Browse files
Copilotsarzhann
andcommitted
Use sessionStorage instead of localStorage for sidebar open-state persistence
Co-authored-by: sarzhann <32760183+sarzhann@users.noreply.github.com> Agent-Logs-Url: https://github.com/vespa-engine/documentation/sessions/13bf9147-a40d-41bc-a44a-297ec880667b
1 parent 9b33bbb commit 45e5a51

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

_includes/sidebar.html

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
{%- endif -%}
9595
{%- endfor -%}
9696
<li class="top">
97-
<details{% if item_contains_current %} open{% endif %}><!-- open so current page is visible when landing via direct link -->
97+
<details data-id="{{ item.title }}"{% if item_contains_current %} open{% endif %}><!-- open so current page is visible when landing via direct link -->
9898
<summary>{{ item.title }}</summary>
9999
{% if item.documents %}
100100
<ul class="child">
@@ -112,7 +112,7 @@
112112
{%- endfor -%}
113113
{%- endif -%}
114114
{%- endfor -%}
115-
<details{% if child_contains_current %} open{% endif %}><!-- open so current page is visible when landing via direct link -->
115+
<details data-id="{{ item.title }}.{{ child.title }}"{% if child_contains_current %} open{% endif %}><!-- open so current page is visible when landing via direct link -->
116116
<summary>{{child.title}}</summary>
117117
<ul class="child">
118118
{% for subchild in child.sub %}
@@ -124,7 +124,7 @@
124124
{%- for ssd in subchild.sub -%}
125125
{%- if ssd.url == page.url -%}{%- assign subchild_contains_current = true -%}{%- endif -%}
126126
{%- endfor -%}
127-
<details{% if subchild_contains_current %} open{% endif %}><!-- open so current page is visible when landing via direct link -->
127+
<details data-id="{{ item.title }}.{{ child.title }}.{{ subchild.title }}"{% if subchild_contains_current %} open{% endif %}><!-- open so current page is visible when landing via direct link -->
128128
<summary>{{subchild.title}}</summary>
129129
<ul class="child">
130130
{% for subsubchild in subchild.sub %}
@@ -155,4 +155,16 @@
155155
{% endfor %}
156156
</ul>
157157
</div>
158+
159+
<script type="application/javascript">
160+
const saved = new Set(JSON.parse(sessionStorage.getItem('expanded') || '[]'));
161+
162+
document.querySelectorAll('details[data-id]').forEach(d => {
163+
if (saved.has(d.dataset.id)) d.open = true;
164+
d.addEventListener('toggle', () => {
165+
if (d.open) saved.add(d.dataset.id); else saved.delete(d.dataset.id);
166+
sessionStorage.setItem('expanded', JSON.stringify([...saved]));
167+
});
168+
});
169+
</script>
158170

0 commit comments

Comments
 (0)