|
1 |
| -import type { QuestionBank, QuestionBankConfig } from "@/lib/types" |
| 1 | +import type { |
| 2 | + ChoiceLetter, |
| 3 | + QuestionBank, |
| 4 | + QuestionBankConfig, |
| 5 | +} from "@/lib/types" |
2 | 6 |
|
3 | 7 | /**
|
4 | 8 | * This file is used to generate the question bank for the quizzes.
|
@@ -30,6 +34,25 @@ import type { QuestionBank, QuestionBankConfig } from "@/lib/types"
|
30 | 34 | * - "what-is-ethereum-1-c-explanation"
|
31 | 35 | * - "what-is-ethereum-1-d-label"
|
32 | 36 | * - "what-is-ethereum-1-d-explanation"
|
| 37 | + * |
| 38 | + * To re-use answer explanations from other choices within the same question, |
| 39 | + * append an optional explanationOverrides array to the question object. |
| 40 | + * This take the format of an array of 1-indexed answer choices to re-use, with |
| 41 | + * the position in the array representing which question to override. First |
| 42 | + * position is "a". |
| 43 | + * |
| 44 | + * Example - Re-use the first answer explanation for all choices: |
| 45 | + * "what-is-ethereum": [ |
| 46 | + * { totalAnswers: 4, correctAnswer: 2, explanationOverrides: [1, 1, 1, 1] } |
| 47 | + * ] |
| 48 | + * |
| 49 | + * With that alteration, requires the following strings in learn-quizzes.json: |
| 50 | + * - "what-is-ethereum-1-prompt" |
| 51 | + * - "what-is-ethereum-1-a-label" |
| 52 | + * - "what-is-ethereum-1-a-explanation" |
| 53 | + * - "what-is-ethereum-1-b-label" |
| 54 | + * - "what-is-ethereum-1-c-label" |
| 55 | + * - "what-is-ethereum-1-d-label" |
33 | 56 | */
|
34 | 57 | const questionBankConfig: QuestionBankConfig = {
|
35 | 58 | "what-is-ethereum": [
|
@@ -137,19 +160,26 @@ const charFromIdx = (idx: number) => String.fromCharCode(97 + idx)
|
137 | 160 | const questionBank = Object.entries(questionBankConfig).reduce(
|
138 | 161 | (acc, [topicKey, value]) => {
|
139 | 162 | for (const [idx, question] of value.entries()) {
|
140 |
| - const { totalAnswers, correctAnswer } = question |
| 163 | + const { totalAnswers, correctAnswer, explanationOverrides } = question |
141 | 164 | const questionKey = `${topicKey}-${idx + 1}`
|
142 | 165 | const questionObject = {
|
143 | 166 | prompt: `${questionKey}-prompt`,
|
144 | 167 | answers: Array(totalAnswers)
|
145 | 168 | .fill(0)
|
146 | 169 | .map((_, i) => {
|
147 |
| - const choice = charFromIdx(i) as "a" | "b" | "c" | "d" |
| 170 | + const choice = charFromIdx(i) as ChoiceLetter |
| 171 | + const exIdx = |
| 172 | + explanationOverrides && explanationOverrides[i] |
| 173 | + ? explanationOverrides[i] - 1 |
| 174 | + : i |
| 175 | + const exLetter = charFromIdx(exIdx) as ChoiceLetter |
| 176 | + |
148 | 177 | const id = `${questionKey}-${choice}`
|
| 178 | + const exId = `${questionKey}-${exLetter}` |
149 | 179 | return {
|
150 | 180 | id,
|
151 | 181 | label: `${id}-label`,
|
152 |
| - explanation: `${id}-explanation`, |
| 182 | + explanation: `${exId}-explanation`, |
153 | 183 | }
|
154 | 184 | }),
|
155 | 185 | correctAnswerId: `${questionKey}-${charFromIdx(correctAnswer - 1)}`,
|
|
0 commit comments