From 28db7e54dbac696ee5b3be684ff29f9a93998f8d Mon Sep 17 00:00:00 2001 From: Greg Albers Date: Mon, 11 Oct 2021 08:44:08 -0700 Subject: [PATCH 1/4] Add file-path partial to convert backslashes --- .../partials/contents-list/closing-tags.html | 13 ++++++++++--- .../partials/contents-list/contents-list.html | 7 +++++-- .../layouts/partials/contents-list/file-path.html | 6 ++++++ 3 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 themes/default/layouts/partials/contents-list/file-path.html diff --git a/themes/default/layouts/partials/contents-list/closing-tags.html b/themes/default/layouts/partials/contents-list/closing-tags.html index 086c7f42f..b2c4c0b36 100644 --- a/themes/default/layouts/partials/contents-list/closing-tags.html +++ b/themes/default/layouts/partials/contents-list/closing-tags.html @@ -1,7 +1,14 @@ {{/* If the .File.Dir of the current page matches the START of the .File.Dir of the next page, we’re still in the same section, so do nothing. Otherwise proceed to next section to add the appropriate number of closing /ul/li tags to close section(s) --------------------------------------------------------------------------- */}} -{{- $currentPageDirectory := (index .AllPages .PageIndex).File.Dir -}} -{{- $nextPageDirectory := (index .AllPages (add .PageIndex 1)).File.Dir -}} +{{- $currentPage := (index .AllPages .PageIndex).File.Dir -}} +{{- $currentPageDirectory := partial "contents-list/file-path.html" $currentPage -}} + +{{- $nextPage := (index .AllPages (add .PageIndex 1)).File.Dir -}} +{{- $nextPageDirectory := "" -}} +{{- if $nextPage }} +{{- $nextPageDirectory = partial "contents-list/file-path.html" $nextPage -}} +{{- end -}} + {{- $findPattern := printf "%s%s" "^" $currentPageDirectory -}} {{- if (findRE $findPattern $nextPageDirectory) -}} @@ -13,7 +20,7 @@ {{/* Find the last page within the same .File.Dir as the current page, if the current page IS the last page, we need to add at least one set of closing /ul/li tags. to determine how many sets of tags are needed, check the sub-section level difference between the current page and the next page. For example, a page with a file directory of `section/sub-section/sub-sub-section/` is at sub-section level of 3. If the next page is at `section/`, with sub-section level of 1, there are 2 levels of difference between them and so we need 2 sets of closing tags. (We use a findRE pattern to count the number of instances of one or more characters followed by a slash in the .File.Dir to determine the sub-section level.) ------------------------------------------------------------------------- */}} {{- $currentPageID := .Page.File.UniqueID -}} - {{- $pagesInSection := where .AllPages "File.Dir" "eq" $currentPageDirectory -}} + {{- $pagesInSection := where .AllPages "File.Dir" "eq" $currentPage -}} {{- $openSections := .openSections -}} {{- range last 1 $pagesInSection -}} diff --git a/themes/default/layouts/partials/contents-list/contents-list.html b/themes/default/layouts/partials/contents-list/contents-list.html index a7f681a63..813c20915 100644 --- a/themes/default/layouts/partials/contents-list/contents-list.html +++ b/themes/default/layouts/partials/contents-list/contents-list.html @@ -85,14 +85,17 @@ {{- $lastSection := "/" -}} {{- $openSections := dict -}} -{{- $renderedSections := .contentsScope -}} +{{- $renderedSections := "" -}} +{{- if .contentsScope -}} +{{- $renderedSections = partial "contents-list/file-path.html" .contentsScope -}} +{{- end -}} {{- $contentsScopePattern := printf "%s%s" "^" $renderedSections -}} {{- $contentsPageID := .contentsPage.File.UniqueID -}}