From 8e38759613c027477764f2f60fbf5ed3550fbca0 Mon Sep 17 00:00:00 2001 From: Peter Mosses <18308236+pdmosses@users.noreply.github.com> Date: Tue, 9 May 2023 17:57:26 +0200 Subject: [PATCH] Fix liquid variable leakage in navigation components (#1243) * Refactor nav, breadcrumbs, children_nav Fix #1118 Improve the modularity of building the nav-panel, breadcrumbs, and children-nav by making them independent. This also significantly simplifies the Liquid code. * Fix order of breadcrumbs * Update breadcrumbs.html Revert inclusion of single breadcrumb for top-level pages. * Update breadcrumbs.html * Update children_nav.html Revert to the previous layout in the HTML, to allow the use of `diff` to check the built site. * Update minimal.html Remove the previously required workaround involving `nav.html`. * Add docs pages about layouts The aim of the initial version of these docs pages is to illustrate the difference between the default and minimal layouts. * Update CHANGELOG.md --- CHANGELOG.md | 4 +- _includes/components/breadcrumbs.html | 58 ++++++-- _includes/components/children_nav.html | 34 ++++- _includes/nav.html | 191 +++---------------------- _includes/sorted_pages.html | 95 ++++++++++++ _layouts/default.html | 2 +- _layouts/minimal.html | 28 +--- docs/layout/layout.md | 40 ++++++ docs/layout/minimal/default-child.md | 8 ++ docs/layout/minimal/minimal-child.md | 8 ++ docs/layout/minimal/minimal.md | 12 ++ 11 files changed, 263 insertions(+), 217 deletions(-) create mode 100644 _includes/sorted_pages.html create mode 100644 docs/layout/layout.md create mode 100644 docs/layout/minimal/default-child.md create mode 100644 docs/layout/minimal/minimal-child.md create mode 100644 docs/layout/minimal/minimal.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 27e1e1d..f18e399 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,12 +20,14 @@ This website includes docs for some new features that are not available in `v0.5 Code changes to `main` that are *not* in the latest release: -- N/A +- Fixed: liquid variable leakage in navigation components by [@pdmosses] in [#1243] Docs changes in `main` that are *not* in the latest release: - N/A +[#1243]: https://github.com/just-the-docs/just-the-docs/pull/1243 + ## Release v0.5.1 Hi all, this is a very small minor patch release that has two small behavioral bugfixes: fixing a regression introduced in `v0.5.0` on Safari versions `<16.4` (broken media query), and the copy code button providing incorrect feedback in insecure browser contexts. This should be a smooth upgrade with no breaking changes. diff --git a/_includes/components/breadcrumbs.html b/_includes/components/breadcrumbs.html index f1bc488..82ad6bd 100644 --- a/_includes/components/breadcrumbs.html +++ b/_includes/components/breadcrumbs.html @@ -1,15 +1,43 @@ -{% unless page.url == "/" %} - {% if page.parent %} - - {% endif %} -{% endunless %} +{%- comment -%} + Include as: {%- include components/breadcrumbs.html -%} + Depends on: page, site. + Results in: HTML for the breadcrumbs component. + Overwrites: + pages_list, parent_page, grandparent_page. +{%- endcomment -%} + +{%- if page.url != "/" and page.parent -%} + + {%- assign pages_list = site[page.collection] + | default: site.html_pages + | where_exp: "item", "item.title != nil" + | where_exp: "item", "item.has_children != nil" -%} + + {%- if page.grand_parent -%} + {%- assign parent_page = pages_list + | where: "title", page.parent + | where: "parent", page.grand_parent + | first -%} + {%- assign grandparent_page = pages_list + | where: "title", page.grand_parent + | first -%} + {%- else -%} + {%- assign parent_page = pages_list + | where: "title", page.parent + | where_exp: "item", "item.parent == nil" + | first -%} + {%- endif -%} + + + +{%- endif -%} diff --git a/_includes/components/children_nav.html b/_includes/components/children_nav.html index e76f98d..ce2482a 100644 --- a/_includes/components/children_nav.html +++ b/_includes/components/children_nav.html @@ -1,9 +1,33 @@ +{%- comment -%} + Include as: {%- include components/children_nav.html -%} + Depends on: page, site. + Results in: HTML for the children-navigation component. + Includes: + sorted_pages.html + toc_heading_custom.html + Overwrites: + child_pages. +{%- endcomment -%} + +{%- if page.has_children == true and page.has_toc != false -%} + {%- assign child_pages = site[page.collection] + | default: site.html_pages + | where: "parent", page.title + | where: "grand_parent", page.parent -%} + + {%- include sorted_pages.html pages = child_pages -%} + + {%- if page.child_nav_order == 'desc' or page.child_nav_order == 'reversed' -%} + {%- assign sorted_pages = sorted_pages | reverse -%} + {%- endif -%} +{%- endif -%} +