Skip to content

Commit 1e0fe47

Browse files
committed
Fix: section page count and total words error
1 parent fa315e7 commit 1e0fe47

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

layouts/projects.html

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,26 @@
66
{{- define "content" -}}
77
{{- $params := partial "function/params.html" -}}
88
{{- $fingerprint := .Scratch.Get "fingerprint" -}}
9+
{{- $pages := .Pages -}}
10+
{{- $hiddenAdapters := .Param "hiddenAdapters" | default false -}}
11+
{{- if $hiddenAdapters -}}
12+
{{- $pages = where $pages "File.IsContentAdapter" "ne" true -}}
13+
{{- end -}}
914
{{- $data := index .Site.Data (printf "projects.%v" .Language) | default .Site.Data.projects -}}
1015
{{- $toc := .Scratch.Get "toc" -}}
1116
{{- $tableOfContents := .Fragments.ToHTML ($toc.startlevel | int) ($toc.endlevel | int) false -}}
1217
{{- $contentToc := ne $tableOfContents `<nav id="TableOfContents"></nav>` -}}
13-
{{- $hasToc := $contentToc | or (gt (len $data) 0) | or (gt .Pages.Len 0) -}}
18+
{{- $hasToc := $contentToc | or (gt (len $data) 0) | or (gt (len $pages) 0) -}}
1419
{{- $showToc := $toc.enable | and $hasToc -}}
20+
{{- $localData := newScratch -}}
21+
{{- $pageCount := 0 -}}
1522
{{- /* Paginate before content */ -}}
16-
{{- $pages := .Pages -}}
17-
{{- $hiddenAdapters := .Param "hiddenAdapters" | default false -}}
18-
{{- if $hiddenAdapters -}}
19-
{{- $pages = where $pages "File.IsContentAdapter" "ne" true -}}
20-
{{- end -}}
2123
{{- if $pages -}}
24+
{{- $pageCount = $pages.Len -}}
25+
{{- /* Total page and word count */ -}}
26+
{{- range $pages -}}
27+
{{- $localData.Add "totalWordCount" .WordCount -}}
28+
{{- end -}}
2229
{{- $pages = $pages.GroupByDate "2006" -}}
2330
{{- with .Site.Params.section.paginate | default .Site.Params.paginate -}}
2431
{{- $pages = $.Paginate $pages . -}}
@@ -77,7 +84,7 @@ <h1 class="single-title animate__animated animate__pulse animate__faster">
7784
{{- $tocFromData = add $tocFromData (printf "<li><a href=\"#%v\">%v</a></li>" ($group.title | anchorize) $group.title) -}}
7885
{{- end -}}
7986
{{- end -}}
80-
{{- if .Pages -}}
87+
{{- if $pages -}}
8188
{{- $tocFromData = add $tocFromData (printf "<li><a href=\"#related-articles\">%v</a></li>" (T "projects.relatedArticles")) -}}
8289
{{- end -}}
8390
{{- with $tocFromData -}}
@@ -151,19 +158,14 @@ <h2 id="{{ $group.title | anchorize }}" class="heading-element">
151158
</div>
152159
{{- end -}}
153160
<hr class="awesome-hr">
154-
{{- if .Pages -}}
161+
{{- if $pages -}}
155162
<h2 id="related-articles" class="heading-element">
156163
<span>{{ T "projects.relatedArticles" }}</span>
157164
<a href="#related-articles" class="heading-mark"><svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg></a>
158165
</h2>
159-
{{- /* Total page and word count */ -}}
160-
{{- $localData := newScratch -}}
161-
{{- range .Pages -}}
162-
{{- $localData.Add "totalWordCount" .WordCount -}}
163-
{{- end -}}
164166
{{- with ($localData.Get "totalWordCount") -}}
165-
<div title="{{- T `section.archiveCounter` $.Pages.Len }} {{ T `section.totalWordCount` . }}" class="group-summary">
166-
{{- T "section.archiveCounter" $.Pages.Len }} & {{ T "section.totalWordCount" (dict "Count" (partial "function/format-number" (dict "NUMBER" .))) -}}
167+
<div title="{{- T `section.archiveCounter` $pageCount }} {{ T `section.totalWordCount` . }}" class="group-summary">
168+
{{- T "section.archiveCounter" $pageCount }} & {{ T "section.totalWordCount" (dict "Count" (partial "function/format-number" (dict "NUMBER" .))) -}}
167169
</div>
168170
{{- end -}}
169171
{{- with $params.sectionSlot -}}

0 commit comments

Comments
 (0)