Skip to content

Commit 8fe3f57

Browse files
authored
generate once, load many (#330)
### Description When the side bar was added to the command page it caused a massive increase in build times (see #321). This was caused by each command page needing to pull every command JSON file into to generate the list. This PR takes a different approach, it adds a page (`/command-list/`), that is generated once, which contains the all the commands formatted as list items. Then, on each command page, it pulls that content in with some simple javascript. Full build times were previously taking 40-70 seconds. After this change, the build times are taking approximately 1.2 seconds. ``` Building site... Checking all internal links with anchors. > Successfully checked 0 internal link(s) with anchors. -> Creating 564 pages (0 orphan) and 8 sections Warning: Highlight language plaintext not found Done in 1.2s. ``` ### Issues Resolved #321 ### Check List - [x] Commits are signed per the DCO using `--signoff` By submitting this pull request, I confirm that my contribution is made under the terms of the BSD-3-Clause License. Signed-off-by: Kyle J. Davis <[email protected]>
1 parent 28f33e3 commit 8fe3f57

File tree

3 files changed

+51
-35
lines changed

3 files changed

+51
-35
lines changed

content/command-list/_index.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
+++
2+
title = "Command List"
3+
template = "command-list.html"
4+
page_template = "blog-page.html"
5+
+++

templates/command-list.html

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{% import "macros/command.html" as commands %}
2+
3+
{% set commands_entries = [] %}
4+
{% set commands_section = get_section(path="commands/_index.md") %}
5+
{% for page in commands_section.pages %}
6+
7+
{% for json_path in [
8+
commands::command_json_path(slug=page.slug),
9+
commands::command_bloom_json_path(slug=page.slug),
10+
commands::command_json_json_path(slug=page.slug),
11+
commands::command_search_json_path(slug=page.slug)
12+
] %}
13+
{% set command_data = load_data(path= json_path, required= false) %}
14+
{% if command_data %}
15+
{% set command_obj_name = commands::command_obj_name(command_data= command_data) %}
16+
{% set list_command_data_obj = command_data[command_obj_name] %}
17+
{% set command_display = command_obj_name %}
18+
{% if list_command_data_obj.container %}
19+
{% set command_display = list_command_data_obj.container ~ " " ~ command_display %}
20+
{% endif %}
21+
{% set command_entry = [
22+
command_display,
23+
page.permalink | safe,
24+
list_command_data_obj.summary,
25+
list_command_data_obj.group
26+
] %}
27+
{% set_global commands_entries = commands_entries | concat(with= [ command_entry ]) %}
28+
{% endif %}
29+
{% endfor %}
30+
{% endfor %}
31+
32+
{% set alpha_entries = commands_entries | sort(attribute="0") %}
33+
{% for entry in alpha_entries %}
34+
<li class="command-list-item"><code><a href="{{ entry[1] }}">{{ entry[0] }}</a></code></li>
35+
{% endfor %}

templates/command-page.html

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -225,34 +225,6 @@ <h3>History</h3>
225225

226226
{% block related_content %}
227227
{# Set up variables for sidebar, similar to commands.html #}
228-
{% set_global group_descriptions = load_data(path= "../_data/groups.json", required= false) %}
229-
{% set commands_entries = [] %}
230-
{% set commands_section = get_section(path="commands/_index.md") %}
231-
{% for page in commands_section.pages %}
232-
{% for json_path in [
233-
commands::command_json_path(slug=page.slug),
234-
commands::command_bloom_json_path(slug=page.slug),
235-
commands::command_json_json_path(slug=page.slug),
236-
commands::command_search_json_path(slug=page.slug)
237-
] %}
238-
{% set command_data = load_data(path= json_path, required= false) %}
239-
{% if command_data %}
240-
{% set command_obj_name = commands::command_obj_name(command_data= command_data) %}
241-
{% set list_command_data_obj = command_data[command_obj_name] %}
242-
{% set command_display = command_obj_name %}
243-
{% if list_command_data_obj.container %}
244-
{% set command_display = list_command_data_obj.container ~ " " ~ command_display %}
245-
{% endif %}
246-
{% set command_entry = [
247-
command_display,
248-
page.permalink | safe,
249-
list_command_data_obj.summary,
250-
list_command_data_obj.group
251-
] %}
252-
{% set_global commands_entries = commands_entries | concat(with= [ command_entry ]) %}
253-
{% endif %}
254-
{% endfor %}
255-
{% endfor %}
256228

257229
<div class="sb-search-container">
258230
<input type="text" id="sidebar-search-box" placeholder="Search within documents" onkeyup="searchSidebarCommands()" />
@@ -266,14 +238,18 @@ <h4>No commands found</h4>
266238
</div>
267239

268240
<h2 id="command-list-title">Alphabetical Command List</h2>
269-
<ul id="command-list">
270-
{% set alpha_entries = commands_entries | sort(attribute="0") %}
271-
{% for entry in alpha_entries %}
272-
<li class="command-list-item"><code><a href="{{ entry[1] }}">{{ entry[0] }}</a></code></li>
273-
{% endfor %}
274-
</ul>
275-
241+
<ul id="command-list"></ul>
276242
<script>
243+
document.addEventListener("DOMContentLoaded", function() {
244+
var
245+
commandListEl = document.getElementById('command-list'),
246+
f = fetch("/command-list/");
247+
248+
f.then((r) => r.text()).then((v) => { commandListEl.innerHTML = v; })
249+
f.catch((error) => { commandListEl.innerHTML = "Could not load command list."; });
250+
});
251+
252+
277253
function searchSidebarCommands() {
278254
var input = document.getElementById("sidebar-search-box").value.toLowerCase();
279255
var commandList = document.getElementById("command-list");

0 commit comments

Comments
 (0)