Skip to content

Commit

Permalink
Merge pull request #201 from thegetty/fix/windows-filepath
Browse files Browse the repository at this point in the history
Fix/ Convert directory paths in contents-list partials to work in Windows
  • Loading branch information
hbalenda committed Oct 25, 2021
2 parents 728d6e2 + b153949 commit eaee2d7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Project versions conform to [Semantic Versioning](https://semver.org/)

## [Unreleased]
- Adds `disableFastRender` option to `quire preview` command
- Adds `contents-list/file-dir` partial to normalize directories in `contents-list`

## [0.20.1]

Expand Down
13 changes: 10 additions & 3 deletions themes/default/layouts/partials/contents-list/closing-tags.html
Original file line number Diff line number Diff line change
@@ -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-dir.html" $currentPage -}}

{{- $nextPage := (index .AllPages (add .PageIndex 1)).File.Dir -}}
{{- $nextPageDirectory := "" -}}
{{- if $nextPage }}
{{- $nextPageDirectory = partial "contents-list/file-dir.html" $nextPage -}}
{{- end -}}

{{- $findPattern := printf "%s%s" "^" $currentPageDirectory -}}

{{- if (findRE $findPattern $nextPageDirectory) -}}
Expand All @@ -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 -}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,17 @@

{{- $lastSection := "/" -}}
{{- $openSections := dict -}}
{{- $renderedSections := .contentsScope -}}
{{- $renderedSections := "" -}}
{{- if .contentsScope -}}
{{- $renderedSections = partial "contents-list/file-dir.html" .contentsScope -}}
{{- end -}}
{{- $contentsScopePattern := printf "%s%s" "^" $renderedSections -}}
{{- $contentsPageID := .contentsPage.File.UniqueID -}}

<ul>
{{- range $index, $page := $pages -}}

{{- $section := .File.Dir -}}
{{- $section := partial "contents-list/file-dir.html" .File.Dir -}}
{{- $sectionLevel := len (findRE "(.+?)/" $section) -}}
{{- $sameAsOpenSection := false -}}

Expand Down
7 changes: 7 additions & 0 deletions themes/default/layouts/partials/contents-list/file-dir.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{/* Uses the Hugo `path.Dir` function to return the given path's directory and normalize it, making it consistent for both Windows and macOS/Linux/Unix users
--------------------------------------------------------------------------- */}}
{{- $fileDir := path.Dir . -}}
{{- if ne $fileDir "/" -}}
{{- $fileDir = printf "%s%s" $fileDir "/" -}}
{{- end -}}
{{- return $fileDir -}}

0 comments on commit eaee2d7

Please sign in to comment.