diff --git a/.gitignore b/.gitignore index 6604da5..7f2818e 100644 --- a/.gitignore +++ b/.gitignore @@ -24,5 +24,6 @@ resources/ #hugo .hugo_build.lock +content/ .DS_Store diff --git a/archetypes/final-test.md b/archetypes/final-test.md index e86d2b0..680f99f 100644 --- a/archetypes/final-test.md +++ b/archetypes/final-test.md @@ -10,6 +10,7 @@ final: true # Indicates that this test is the final exam and must be completed t questions: # Multiple Choice Question (Single Answer) + # NOTE: The 'marks' field must be a positive number (greater than 0). Negative or zero values will cause a build error. - id: "q1" text: "What keyword is used to define a function in Go?" type: "multiple_answers" diff --git a/archetypes/optional-test.md b/archetypes/optional-test.md index b37702f..d3a5c8c 100644 --- a/archetypes/optional-test.md +++ b/archetypes/optional-test.md @@ -10,6 +10,7 @@ is_optional: true # Indicates that this test is optional and does not need to be questions: # Multiple Choice Question (Single Answer) + # NOTE: The 'marks' field must be a positive number (greater than 0). Negative or zero values will cause a build error. - id: "q1" text: "What keyword is used to define a function in Go?" type: "multiple_answers" diff --git a/archetypes/test.md b/archetypes/test.md index 167c0ac..f6c7f73 100644 --- a/archetypes/test.md +++ b/archetypes/test.md @@ -12,7 +12,7 @@ questions: # Multiple Choice Question (Single Answer) - id: "q1" text: "What keyword is used to define a function in Go?" - type: "multiple-answers" + type: "multiple_answers" marks: 2 explanation: "The 'func' keyword is used to declare functions in Go, similar to how 'function' is used in JavaScript." options: diff --git a/layouts/partials/test/single.html b/layouts/partials/test/single.html index 797ff82..b6834d9 100644 --- a/layouts/partials/test/single.html +++ b/layouts/partials/test/single.html @@ -20,6 +20,14 @@ {{- $questionIds = $questionIds | append (string $id) -}} {{- end -}} + +{{- range $index, $question := $p.questions -}} + {{- $marks := or $question.marks 0 -}} + {{- if le $marks 0 -}} + {{- errorf "Question %d (id: %s) has invalid marks value '%v'. Marks must be greater than 0. Please update the 'marks' field with a positive number. [ %s ]" (add $index 1) $question.id $marks $.File.Path -}} + {{- end -}} +{{- end -}} + {{- $numberOfQuestionSets := div (len $p.questions) $totalQuestionsPerSet -}} {{- $total := 0 -}}