mirror of
https://github.com/snachodog/just-the-docs.git
synced 2025-09-13 05:13:33 -06:00
Quicker build (#1397)
This PR uses the cached site-nav to determine the position of each page in the navigation hierarchy. [Profiling](https://just-the-docs.github.io/just-the-docs-tests/tests/profiles/index/) shows that it significantly reduces the v0.7.0 build time for larger sites – especially with Jekyll 3. The improvement is due mainly to the elimination of loops and filters that depended on the entire site. For example: - [endoflife.date](https://just-the-docs.github.io/just-the-docs-tests/tests/profiles/endoflife.date/index/) drops from 32s to 11s - [machinetranslate.org](https://just-the-docs.github.io/just-the-docs-tests/tests/profiles/machinetranslate.org/index/) drops from 267s to ~~73s~~ 56s ### Testing [Just the Docs Tests](https://just-the-docs.github.io/just-the-docs-tests/) is currently built using this PR branch. With JS disabled, the highlighting and unfolding of the navigation panel should be as with v0.7.0. A diff of the tests site built with this PR branch compared to v0.7.0 should report no significant changes. For more rigorous testing, diffs of variants of the tests site should also be inspected.
This commit is contained in:
@@ -1,19 +1,17 @@
|
||||
{%- comment -%}
|
||||
Include as: {%- include css/activation.scss.liquid -%}
|
||||
Depends on: page, site.
|
||||
Results in: page-dependent (non-nested) CSS rules for inclusion in a head style element,
|
||||
which needs to be suppressed when JS is enabled.
|
||||
Includes:
|
||||
sorted_pages.html.
|
||||
Depends on: page.
|
||||
Results in: page-dependent CSS rules for inclusion in a style element,
|
||||
which needs to be disabled when JS is enabled.
|
||||
Includes: components/site_nav.html.
|
||||
Overwrites:
|
||||
activation_no_nav_link, activation_pages, activation_pages_top_size, activation_page, activation_title,
|
||||
activation_first_level, activation_second_level, activation_third_level,
|
||||
activation_first_level_reversed, activation_second_level_reversed,
|
||||
activation_first_level_index, activation_second_level_index, activation_third_level_index,
|
||||
activation_index, activation_collection_prefix, activation_other_collection_prefix.
|
||||
activation_no_nav_link, nav_list_link, site_nav,
|
||||
nav_list, nav_list_end, nav_list_item, nav_category_list,
|
||||
nav_list_link_prefix, nav_splits, nav_split, nav_levels,
|
||||
nav_list_less, nav_list_count, nav_end_less, nav_end_count,
|
||||
nav_index, nav_slice_size,
|
||||
activation_collection_prefix, activation_other_collection_prefix.
|
||||
Should not be cached, because it depends on page.
|
||||
(For a site with only top-level pages, the rendering of this file is always empty.
|
||||
This property could be detected, and used to reduce the build time for such sites.)
|
||||
{%- endcomment -%}
|
||||
|
||||
{%- comment -%}
|
||||
@@ -37,89 +35,163 @@
|
||||
{%- endif %}
|
||||
{% endcapture -%}
|
||||
|
||||
{%- if page.title == nil or page.nav_exclude == true -%}
|
||||
{%- capture nav_list_link -%}
|
||||
<a href="{{ page.url | relative_url }}" class="nav-list-link">
|
||||
{%- endcapture -%}
|
||||
|
||||
{{ activation_no_nav_link }}
|
||||
{%- capture site_nav -%}
|
||||
{%- include_cached components/site_nav.html -%}
|
||||
{%- endcapture -%}
|
||||
|
||||
{%- else -%}
|
||||
{%- if site_nav contains nav_list_link -%}
|
||||
|
||||
{%- assign activation_pages = site[page.collection]
|
||||
| default: site.html_pages
|
||||
| where_exp: "item", "item.title != nil"
|
||||
| where_exp: "item", "item.nav_exclude != true" -%}
|
||||
{%- capture nav_list -%}
|
||||
<ul class="nav-list
|
||||
{%- endcapture -%}
|
||||
|
||||
{%- assign activation_first_level_index = nil -%}
|
||||
{%- assign activation_second_level_index = nil -%}
|
||||
{%- assign activation_third_level_index = nil -%}
|
||||
{%- assign activation_first_level_reversed = nil -%}
|
||||
{%- assign activation_second_level_reversed = nil -%}
|
||||
{%- assign nav_list_end = "</ul>" -%}
|
||||
|
||||
{%- capture nav_list_item -%}
|
||||
<li class="nav-list-item
|
||||
{%- endcapture -%}
|
||||
|
||||
{%- capture nav_category_list -%}
|
||||
<ul class="nav-list nav-category-list">
|
||||
{%- endcapture -%}
|
||||
|
||||
{%- assign nav_list_link_prefix =
|
||||
site_nav | split: nav_list_link | first | append: nav_list_link -%}
|
||||
|
||||
{%- assign nav_splits =
|
||||
nav_list_link_prefix | split: nav_list_item | pop -%}
|
||||
|
||||
{%- assign nav_levels = "" | split: "" | push: 1 -%}
|
||||
|
||||
{%- comment -%}
|
||||
The pattern of occurrences of list and list-item tags in the site_nav string
|
||||
is included in the language defined by the following context-free grammar:
|
||||
|
||||
site_nav = PAGES? EXTERNALS? COLLECTION*
|
||||
|
||||
PAGES = nav_list (nav_list_item PAGES?)+ nav_list_end
|
||||
|
||||
EXTERNALS = nav_list nav_list_item+ nav_list_end
|
||||
|
||||
COLLECTION = nav_list (nav_list_item PAGES?)* nav_list_end
|
||||
| nav_category_list
|
||||
nav_list_item nav_list (nav_list_item PAGES?)* nav_list_end
|
||||
nav_list_end
|
||||
|
||||
To determine the path in the site_nav to the nav_list_link for the current page,
|
||||
the prefix of nav_list_link in site_nav is split at each nav_list_item to give
|
||||
an array of nav_splits.
|
||||
|
||||
In site_nav, occurrences of nav_list must be separated by at least one
|
||||
nav_list_item or nav_list_end. Moreover, when a nav_list_end is followed by a
|
||||
nav_list without an intervening nav_list_item, that nav_list must start either
|
||||
a list of external links or a collection. And when a nav_list is followed by a
|
||||
nav_list_end without an intervening nav_list_item, they form an empty collection.
|
||||
|
||||
nav_levels is the path determined by the previously inspected nav_splits.
|
||||
How many times nav_list and nav_list_end occur in the current nav_split
|
||||
determines how to update the path.
|
||||
|
||||
A nav_split can contain any number of empty non-foldable collections.
|
||||
The path element produced by the outer nav_list of a foldable collection is
|
||||
irrelevant; it is set to zero and subsequently removed.
|
||||
|
||||
The number of occurrences of a string in a nav_split is computed by removing
|
||||
them all, then dividing the resulting size difference by the length of the string.
|
||||
|
||||
Case analysis on (nav_list_count, nav_list_end_count):
|
||||
|
||||
- when (0, 0), the nav_split was between two nav_list_items at the same level;
|
||||
|
||||
- when (0, N+1), all the nav_list_ends in the nav_split are in PAGES or in one
|
||||
COLLECTION;
|
||||
|
||||
- when (M+1, 0), M must be 0 (because two nav_lists in the same nav_split must
|
||||
be separated by at least one nav_list_end);
|
||||
|
||||
- when (M+1, N+1), the nav_split must contain either:
|
||||
- the end of PAGES followed by the start of EXTERNALS, or
|
||||
- the end of PAGES followed by the start of a COLLECTION, or
|
||||
- the end of EXTERNALS followed by the start of a COLLECTION, or
|
||||
- the end of one COLLECTION followed by the start of another, or
|
||||
- (in the first nav_split) one or more empty non-foldable COLLECTIONS
|
||||
followed by the start of a COLLECTION.
|
||||
In general, nav_levels[0] here needs to be incremented by nav_list_count.
|
||||
However, a nav_split that contains the end of an empty foldable collection
|
||||
followed by the just the start of a collection has two occurrences of nav_list,
|
||||
and the increment needs to be one less; similarly when the first nav_split
|
||||
starts with an empty non-foldable collection.
|
||||
{%- endcomment %}
|
||||
|
||||
{%- for nav_split in nav_splits -%}
|
||||
|
||||
{%- assign nav_list_less = nav_split | remove: nav_list -%}
|
||||
{%- assign nav_list_count =
|
||||
nav_split.size | minus: nav_list_less.size |
|
||||
divided_by: nav_list.size -%}
|
||||
|
||||
{%- assign nav_list_end_less = nav_split | remove: nav_list_end -%}
|
||||
{%- assign nav_list_end_count =
|
||||
nav_split.size | minus: nav_list_end_less.size |
|
||||
divided_by: nav_list_end.size -%}
|
||||
|
||||
{%- if nav_list_count == 0 and nav_list_end_count == 0 -%}
|
||||
|
||||
{%- assign nav_index = nav_levels[-1] | plus: 1 -%}
|
||||
{%- assign nav_levels = nav_levels | pop | push: nav_index -%}
|
||||
|
||||
{%- elsif nav_list_count == 0 and nav_list_end_count >= 1 -%}
|
||||
|
||||
{%- assign nav_slice_size = nav_levels.size | minus: nav_list_end_count -%}
|
||||
{%- assign nav_levels = nav_levels | slice: 0, nav_slice_size -%}
|
||||
{%- assign nav_index = nav_levels[-1] | plus: 1 -%}
|
||||
{%- assign nav_levels = nav_levels | pop | push: nav_index -%}
|
||||
|
||||
{%- elsif nav_list_count == 1 and nav_list_end_count == 0 -%}
|
||||
|
||||
{%- if nav_split contains nav_category_list -%}
|
||||
{%- assign nav_levels = nav_levels | push: 0 -%}
|
||||
{%- else -%}
|
||||
{%- assign nav_levels = nav_levels | push: 1 -%}
|
||||
{%- endif -%}
|
||||
|
||||
{%- elsif nav_list_count >= 1 and nav_list_end_count >= 1 -%}
|
||||
|
||||
{%- assign nav_index = nav_levels[0] | plus: nav_list_count -%}
|
||||
{%- if nav_levels[-1] == 0 or forloop.first -%}
|
||||
{%- assign nav_index = nav_index | minus: 1 -%}
|
||||
{%- endif -%}
|
||||
{%- assign nav_levels = nav_levels | slice: 0, 0 | push: nav_index -%}
|
||||
{%- if nav_split contains nav_category_list -%}
|
||||
{%- assign nav_levels = nav_levels | push: 0 -%}
|
||||
{%- else -%}
|
||||
{%- assign nav_levels = nav_levels | push: 1 -%}
|
||||
{%- endif -%}
|
||||
|
||||
{%- endif -%}
|
||||
|
||||
{%- endfor -%}
|
||||
|
||||
{%- assign nav_levels = nav_levels | where_exp: "item", "item >= 1" -%}
|
||||
|
||||
{%- endif -%}
|
||||
|
||||
{%- comment -%}
|
||||
The generated CSS depends on the position of the current page in each level in
|
||||
the navigation.
|
||||
{%- endcomment -%}
|
||||
|
||||
{%- assign activation_title = page.grand_parent | default: page.parent | default: page.title -%}
|
||||
{%- assign activation_first_level = activation_pages
|
||||
| where_exp: "item", "item.parent == nil" -%}
|
||||
{%- include sorted_pages.html pages = activation_first_level -%}
|
||||
{%- for activation_page in sorted_pages -%}
|
||||
{%- if activation_page.title == activation_title -%}
|
||||
{%- assign activation_first_level_index = forloop.index -%}
|
||||
{%- assign activation_first_level_reversed = activation_page.child_nav_order -%}
|
||||
{%- break -%}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
|
||||
{%- if activation_first_level_index == nil -%}
|
||||
{%- if nav_levels[1] == nil -%}
|
||||
|
||||
{{ activation_no_nav_link }}
|
||||
|
||||
{%- else -%}
|
||||
|
||||
{%- if page.grand_parent -%}
|
||||
{%- assign activation_title = page.parent -%}
|
||||
{%- assign activation_second_level = activation_pages
|
||||
| where_exp: "item", "item.grand_parent == nil"
|
||||
| where_exp: "item", "item.parent == page.grand_parent" -%}
|
||||
{%- elsif page.parent -%}
|
||||
{%- assign activation_title = page.title -%}
|
||||
{%- assign activation_second_level = activation_pages
|
||||
| where_exp: "item", "item.grand_parent == nil"
|
||||
| where_exp: "item", "item.parent == page.parent" -%}
|
||||
{%- endif -%}
|
||||
{%- if page.parent -%}
|
||||
{%- include sorted_pages.html pages = activation_second_level -%}
|
||||
{%- for activation_page in sorted_pages -%}
|
||||
{%- if activation_page.title == activation_title -%}
|
||||
{%- assign activation_second_level_index = forloop.index -%}
|
||||
{%- assign activation_second_level_reversed = activation_page.child_nav_order -%}
|
||||
{%- if activation_first_level_reversed -%}
|
||||
{%- assign activation_second_level_index = sorted_pages | size | plus: 1 | minus: activation_second_level_index -%}
|
||||
{%- endif -%}
|
||||
{%- break -%}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
{%- endif -%}
|
||||
|
||||
{%- if page.grand_parent -%}
|
||||
{%- assign activation_third_level = activation_pages
|
||||
| where_exp: "item", "item.parent == page.parent"
|
||||
| where_exp: "item", "item.grand_parent == page.grand_parent" -%}
|
||||
{%- include sorted_pages.html pages = activation_third_level -%}
|
||||
{%- assign activation_third_level = sorted_pages -%}
|
||||
{%- for activation_page in sorted_pages -%}
|
||||
{%- if activation_page.title == page.title -%}
|
||||
{%- assign activation_third_level_index = forloop.index -%}
|
||||
{%- if activation_second_level_reversed -%}
|
||||
{%- assign activation_third_level_index = sorted_pages | size | plus: 1 | minus: activation_third_level_index -%}
|
||||
{%- endif -%}
|
||||
{%- break -%}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
{%- endif -%}
|
||||
|
||||
{%- if activation_second_level_index == nil and activation_third_level_index -%}
|
||||
{%- if nav_levels[2] == nil and nav_levels[3] -%}
|
||||
|
||||
{{ activation_no_nav_link }}
|
||||
|
||||
@@ -158,34 +230,14 @@
|
||||
|
||||
{%- else -%}
|
||||
|
||||
{%- for activation_collection in site.just_the_docs.collections -%}
|
||||
{%- if activation_collection[0] == page.collection -%}
|
||||
{%- assign activation_index = forloop.index -%}
|
||||
{%- break -%}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
|
||||
{%- assign activation_pages_top_size = site.html_pages
|
||||
| where_exp:"item", "item.title != nil"
|
||||
| where_exp:"item", "item.parent == nil"
|
||||
| where_exp:"item", "item.nav_exclude != true"
|
||||
| size -%}
|
||||
{%- if activation_pages_top_size > 0 -%}
|
||||
{%- assign activation_index = activation_index | plus: 1 -%}
|
||||
{%- endif -%}
|
||||
|
||||
{%- if site.nav_external_links -%}
|
||||
{%- assign activation_index = activation_index | plus: 1 -%}
|
||||
{%- endif -%}
|
||||
|
||||
{%- capture activation_collection_prefix -%}
|
||||
.site-nav > ul:nth-of-type({{ activation_index }})
|
||||
.site-nav > ul:nth-of-type({{ nav_levels[0] }})
|
||||
{%- if site.just_the_docs.collections[page.collection].nav_fold %} > li > ul
|
||||
{%- endif -%}
|
||||
{%- endcapture -%}
|
||||
|
||||
{%- capture activation_other_collection_prefix -%}
|
||||
.site-nav > ul:not(:nth-of-type({{ activation_index }}))
|
||||
.site-nav > ul:not(:nth-of-type({{ nav_levels[0] }}))
|
||||
{%- endcapture -%}
|
||||
|
||||
{%- endif -%}
|
||||
@@ -197,25 +249,25 @@
|
||||
and children of the current page.
|
||||
{%- endcomment %}
|
||||
|
||||
{% if activation_third_level_index -%}
|
||||
{% if nav_levels[3] -%}
|
||||
|
||||
{{ activation_collection_prefix }} > li > a,
|
||||
{{ activation_collection_prefix }} > li > ul > li > a,
|
||||
{{ activation_collection_prefix }} > li > ul > li > ul > li:not(:nth-child({{ activation_third_level_index }})) > a {
|
||||
{{ activation_collection_prefix }} > li > ul > li > ul > li:not(:nth-child({{ nav_levels[3] }})) > a {
|
||||
background-image: none;
|
||||
}
|
||||
|
||||
{%- elsif activation_second_level_index -%}
|
||||
{%- elsif nav_levels[2] -%}
|
||||
|
||||
{{ activation_collection_prefix }} > li > a,
|
||||
{{ activation_collection_prefix }} > li > ul > li:not(:nth-child({{ activation_second_level_index }})) > a,
|
||||
{{ activation_collection_prefix }} > li > ul > li:not(:nth-child({{ nav_levels[2] }})) > a,
|
||||
{{ activation_collection_prefix }} > li > ul > li > ul > li > a {
|
||||
background-image: none;
|
||||
}
|
||||
|
||||
{%- else -%}
|
||||
|
||||
{{ activation_collection_prefix }} > li:not(:nth-child({{ activation_first_level_index }})) > a,
|
||||
{{ activation_collection_prefix }} > li:not(:nth-child({{ nav_levels[1] }})) > a,
|
||||
{{ activation_collection_prefix }} > li > ul > li > a,
|
||||
{{ activation_collection_prefix }} > li > ul > li > ul > li > a {
|
||||
background-image: none;
|
||||
@@ -236,9 +288,9 @@
|
||||
The following rule styles the link to the current page.
|
||||
{%- endcomment %}
|
||||
|
||||
{{ activation_collection_prefix }} > li:nth-child({{ activation_first_level_index }})
|
||||
{%- if activation_second_level_index %} > ul > li:nth-child({{ activation_second_level_index }})
|
||||
{%- if activation_third_level_index %} > ul > li:nth-child({{ activation_third_level_index }})
|
||||
{{ activation_collection_prefix }} > li:nth-child({{ nav_levels[1] }})
|
||||
{%- if nav_levels[2] %} > ul > li:nth-child({{ nav_levels[2] }})
|
||||
{%- if nav_levels[3] %} > ul > li:nth-child({{ nav_levels[3] }})
|
||||
{%- endif -%}
|
||||
{%- endif %} > a {
|
||||
font-weight: 600;
|
||||
@@ -259,9 +311,9 @@
|
||||
{%- if site.just_the_docs.collections %}
|
||||
.site-nav > ul.nav-category-list > li > button svg,
|
||||
{% endif -%}
|
||||
{{ activation_collection_prefix }} > li:nth-child({{ activation_first_level_index }}) > button svg
|
||||
{%- if activation_second_level_index -%},
|
||||
{{ activation_collection_prefix }} > li:nth-child({{ activation_first_level_index }}) > ul > li:nth-child({{ activation_second_level_index }}) > button svg
|
||||
{{ activation_collection_prefix }} > li:nth-child({{ nav_levels[1] }}) > button svg
|
||||
{%- if nav_levels[2] -%},
|
||||
{{ activation_collection_prefix }} > li:nth-child({{ nav_levels[1] }}) > ul > li:nth-child({{ nav_levels[2] }}) > button svg
|
||||
{%- endif %} {
|
||||
transform: rotate(-90deg);
|
||||
}
|
||||
@@ -269,13 +321,12 @@
|
||||
{%- if site.just_the_docs.collections %}
|
||||
.site-nav > ul.nav-category-list > li.nav-list-item > ul.nav-list,
|
||||
{% endif -%}
|
||||
{{ activation_collection_prefix }} > li.nav-list-item:nth-child({{ activation_first_level_index }}) > ul.nav-list
|
||||
{%- if activation_second_level_index %},
|
||||
{{ activation_collection_prefix }} > li.nav-list-item:nth-child({{ activation_first_level_index }}) > ul.nav-list > li.nav-list-item:nth-child({{ activation_second_level_index }}) > ul.nav-list
|
||||
{{ activation_collection_prefix }} > li.nav-list-item:nth-child({{ nav_levels[1] }}) > ul.nav-list
|
||||
{%- if nav_levels[2] %},
|
||||
{{ activation_collection_prefix }} > li.nav-list-item:nth-child({{ nav_levels[1] }}) > ul.nav-list > li.nav-list-item:nth-child({{ nav_levels[2] }}) > ul.nav-list
|
||||
{%- endif %} {
|
||||
display: block;
|
||||
}
|
||||
|
||||
{%- endif -%}
|
||||
{%- endif -%}
|
||||
{%- endif -%}
|
||||
|
Reference in New Issue
Block a user