|
1 |
| -{{- $isFinal := false -}} |
| 1 | + |
2 | 2 | {{- $page := . -}}
|
3 |
| -{{- $currentWeight := or $page.Params.weight $page.Params.Order 0 -}} |
4 |
| -{{- $maxWeight := 0 -}} |
5 |
| - |
6 |
| -{{- with $page.Parent -}} |
7 |
| - {{- range .Pages -}} |
8 |
| - {{- if eq .Params.Type "test" -}} |
9 |
| - {{- $siblingWeight := or .Params.weight .Params.Order 0 -}} |
10 |
| - {{- if gt $siblingWeight $maxWeight -}} |
11 |
| - {{- $maxWeight = $siblingWeight -}} |
12 |
| - {{- end -}} |
13 |
| - {{- end -}} |
14 |
| - {{- end -}} |
15 |
| -{{- end -}} |
| 3 | +{{- $isFinal := false -}} |
16 | 4 |
|
17 |
| -{{- if and (eq $page.Params.Type "test") (or (eq $currentWeight $maxWeight) (gt $maxWeight $currentWeight)) -}} |
| 5 | +{{/* ✅ Case 1: Explicitly marked as final in front matter */}} |
| 6 | +{{- if $page.Params.final -}} |
18 | 7 | {{- $isFinal = true -}}
|
19 |
| -{{- end -}} |
20 | 8 |
|
21 |
| -{{- if $page.Params.final -}} |
| 9 | +{{/* ✅ Case 2: Only one page in the section — assume it's final */}} |
| 10 | +{{- else if eq (len $page.Parent.Pages) 1 -}} |
22 | 11 | {{- $isFinal = true -}}
|
| 12 | + |
| 13 | +{{/* ✅ Case 3: Determine based on siblings */}} |
| 14 | +{{- else -}} |
| 15 | + |
| 16 | + {{- $testPages := where $page.Parent.Pages "Type" "test" -}} |
| 17 | + {{- $lastPage := index $testPages (sub (len $testPages) 1) -}} |
| 18 | + |
| 19 | + {{/* 🔍 Find sibling pages of type "test" that are explicitly marked as final */}} |
| 20 | + {{- $finalTestPages := where $testPages "Params.final" true -}} |
| 21 | + |
| 22 | + {{/* if some manually defined final pages then set as false */}} |
| 23 | + {{- if gt (len $finalTestPages) 0 -}} |
| 24 | + {{- $isFinal = false -}} |
| 25 | + |
| 26 | + {{/* if no manually defined final pages then set as true */}} |
| 27 | + {{- else if eq $page $lastPage -}} |
| 28 | + {{- $isFinal = true -}} |
| 29 | + {{- end -}} |
| 30 | + |
23 | 31 | {{- end -}}
|
24 | 32 |
|
25 |
| -{{- if and $isFinal (eq $page.Params.is_optional true) -}} |
26 |
| - {{- errorf "Final test cannot be optional: %s" $page.RelPermalink -}} |
| 33 | +{{/* ❌ Disallow optional final tests */}} |
| 34 | +{{- if and $isFinal (eq $page.Params.is_optional true) -}} |
| 35 | + {{- errorf "Final test cannot be optional: %s" $page.RelPermalink -}} |
27 | 36 | {{- end -}}
|
28 | 37 |
|
29 | 38 | {{- return $isFinal -}}
|
0 commit comments