Skip to content
78 changes: 47 additions & 31 deletions templates/command-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -224,35 +224,39 @@ <h3>History</h3>
{% endblock main_content %}

{% block related_content %}
{# Set up variables for sidebar, similar to commands.html #}
{% set_global group_descriptions = load_data(path= "../_data/groups.json", required= false) %}
{% set commands_entries = [] %}
{% set commands_section = get_section(path="commands/_index.md") %}
{% for page in commands_section.pages %}
{% for json_path in [
commands::command_json_path(slug=page.slug),
commands::command_bloom_json_path(slug=page.slug),
commands::command_json_json_path(slug=page.slug),
commands::command_search_json_path(slug=page.slug)
] %}
{% set command_data = load_data(path= json_path, required= false) %}
{% if command_data %}
{% set command_obj_name = commands::command_obj_name(command_data= command_data) %}
{% set list_command_data_obj = command_data[command_obj_name] %}
{% set command_display = command_obj_name %}
{% if list_command_data_obj.container %}
{% set command_display = list_command_data_obj.container ~ " " ~ command_display %}
{# Use cached global variable if available to avoid recomputing command sidebar data on every page #}
{% if not cached_commands_entries %}
{# Compute commands entries once and cache globally #}
{% set_global cached_commands_entries = [] %}
{% set_global group_descriptions = load_data(path= "../_data/groups.json", required= false) %}
{% set commands_section = get_section(path="commands/_index.md") %}
{% for page in commands_section.pages %}
{% for json_path in [
commands::command_json_path(slug=page.slug),
commands::command_bloom_json_path(slug=page.slug),
commands::command_json_json_path(slug=page.slug),
commands::command_search_json_path(slug=page.slug)
] %}
{% set command_data = load_data(path= json_path, required= false) %}
{% if command_data %}
{% set command_obj_name = commands::command_obj_name(command_data= command_data) %}
{% set list_command_data_obj = command_data[command_obj_name] %}
{% set command_display = command_obj_name %}
{% if list_command_data_obj.container %}
{% set command_display = list_command_data_obj.container ~ " " ~ command_display %}
{% endif %}
{% set command_entry = [
command_display,
page.permalink | safe,
list_command_data_obj.summary,
list_command_data_obj.group
] %}
{% set_global cached_commands_entries = cached_commands_entries | concat(with= [ command_entry ]) %}
{% endif %}
{% set command_entry = [
command_display,
page.permalink | safe,
list_command_data_obj.summary,
list_command_data_obj.group
] %}
{% set_global commands_entries = commands_entries | concat(with= [ command_entry ]) %}
{% endif %}
{% endfor %}
{% endfor %}
{% endfor %}
{% endif %}
{% set commands_entries = cached_commands_entries %}

<div class="sb-search-container">
<input type="text" id="sidebar-search-box" placeholder="Search within documents" onkeyup="searchSidebarCommands()" />
Expand All @@ -267,10 +271,22 @@ <h4>No commands found</h4>

<h2 id="command-list-title">Alphabetical Command List</h2>
<ul id="command-list">
{% set alpha_entries = commands_entries | sort(attribute="0") %}
{% for entry in alpha_entries %}
<li class="command-list-item"><code><a href="{{ entry[1] }}">{{ entry[0] }}</a></code></li>
{% endfor %}
{% if commands_entries %}
{% set first_entry = commands_entries | first %}
{% if first_entry.display %}
{# Pre-generated data format: array of objects with display, permalink, summary, group #}
{% set alpha_entries = commands_entries | sort(attribute="display") %}
{% for entry in alpha_entries %}
<li class="command-list-item"><code><a href="{{ entry.permalink }}">{{ entry.display }}</a></code></li>
{% endfor %}
{% else %}
{# Fallback format: array of arrays [display, permalink, summary, group] #}
{% set alpha_entries = commands_entries | sort(attribute="0") %}
{% for entry in alpha_entries %}
<li class="command-list-item"><code><a href="{{ entry[1] }}">{{ entry[0] }}</a></code></li>
{% endfor %}
{% endif %}
{% endif %}
</ul>

<script>
Expand Down