Skip to content

Commit 6be8b4c

Browse files
authored
Merge pull request #76 from layer5io/exam
update prerequisites and final quiz
2 parents 320d738 + 5cc9d2b commit 6be8b4c

File tree

3 files changed

+34
-22
lines changed

3 files changed

+34
-22
lines changed

layouts/partials/test/collect-prerequisites.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{/*
1+
{{/*
22
Usage:
33
{{ partial "collect-prerequisites.html" . }}
44
Returns:
@@ -13,11 +13,12 @@
1313
*/}}
1414

1515
{{- $isFinal := partial "test/is-final.html" $ctx -}}
16+
{{- $currentId := partial "id.html" $ctx -}}
1617

1718
{{- if (eq $isFinal true) -}}
1819

1920
{{- range $ctx.Parent.Pages -}}
20-
{{- if in (slice "course" "module" "test") .Type -}}
21+
{{- if and (in (slice "course" "module" "test") .Type) (ne $ctx .) -}}
2122
{{- if eq (.Params.is_optional | default false) false -}}
2223
{{ $id := partial "id.html" . }}
2324
{{- $item := dict

layouts/partials/test/is-final.html

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,38 @@
1-
{{- $isFinal := false -}}
1+
22
{{- $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 -}}
164

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 -}}
187
{{- $isFinal = true -}}
19-
{{- end -}}
208

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 -}}
2211
{{- $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+
2331
{{- end -}}
2432

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 -}}
2736
{{- end -}}
2837

2938
{{- return $isFinal -}}

layouts/partials/validate-level.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
{{- if in (slice "beginner" "intermediate" "advanced") $level -}}
33
{{ $level }}
44
{{- else -}}
5-
{{ warnf "Invalid level: %s in %s. Defaulting to beginner." $level .File.Path }}
5+
{{- if and ( eq $level "" (in (slice "learning-path" "challenge" "exam") .Type) ) -}}
6+
{{ warnf "Invalid level: %s in %s. Defaulting to beginner." $level .File.Path }}
7+
{{- end -}}
68
beginner
79
{{- end -}}

0 commit comments

Comments
 (0)