Skip to content

Commit ed10d10

Browse files
Copilotmadolson
andcommitted
Implement cached command sidebar using global variables instead of pre-generation script
Co-authored-by: madolson <34459052+madolson@users.noreply.github.com>
1 parent 9876dc9 commit ed10d10

File tree

3 files changed

+6
-119
lines changed

3 files changed

+6
-119
lines changed

README.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,6 @@ From the root directory of this repo run:
8888
../valkey-bloom/src/commands ../valkey-json/src/commands ../valkey-search/src/commands
8989
```
9090

91-
After setting up the command files, generate the command sidebar data for optimal build performance:
92-
93-
```shell
94-
# Run this after init-commands.sh or when command metadata changes
95-
./build/generate-sidebar-data.sh
96-
```
97-
98-
This script pre-processes all command JSON files into a single `_data/commands_sidebar.json` file, which dramatically improves build times by avoiding redundant file operations across hundreds of command pages.
99-
10091
Then, restart Zola.
10192
Point your browser at `http://127.0.0.1:1111/commands/` and you should see the fully populated list of topics.
10293
All files created in this process are ignored by git.

build/generate-sidebar-data.sh

Lines changed: 0 additions & 104 deletions
This file was deleted.

templates/command-page.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,11 @@ <h3>History</h3>
224224
{% endblock main_content %}
225225

226226
{% block related_content %}
227-
{# Load pre-generated command sidebar data instead of processing individual files #}
228-
{% set commands_entries = load_data(path="../_data/commands_sidebar.json", required=false) %}
229-
{% if not commands_entries %}
230-
{# Fallback to the old method if sidebar data is not available #}
227+
{# Use cached global variable if available to avoid recomputing command sidebar data on every page #}
228+
{% if not cached_commands_entries %}
229+
{# Compute commands entries once and cache globally #}
230+
{% set_global cached_commands_entries = [] %}
231231
{% set_global group_descriptions = load_data(path= "../_data/groups.json", required= false) %}
232-
{% set commands_entries = [] %}
233232
{% set commands_section = get_section(path="commands/_index.md") %}
234233
{% for page in commands_section.pages %}
235234
{% for json_path in [
@@ -252,11 +251,12 @@ <h3>History</h3>
252251
list_command_data_obj.summary,
253252
list_command_data_obj.group
254253
] %}
255-
{% set_global commands_entries = commands_entries | concat(with= [ command_entry ]) %}
254+
{% set_global cached_commands_entries = cached_commands_entries | concat(with= [ command_entry ]) %}
256255
{% endif %}
257256
{% endfor %}
258257
{% endfor %}
259258
{% endif %}
259+
{% set commands_entries = cached_commands_entries %}
260260

261261
<div class="sb-search-container">
262262
<input type="text" id="sidebar-search-box" placeholder="Search within documents" onkeyup="searchSidebarCommands()" />

0 commit comments

Comments
 (0)