Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mcq): support note for option #76

Merged
merged 2 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/gold-news-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'anki-templates': minor
---

feat(mcq): support note for option (支持选项笔记)
22 changes: 9 additions & 13 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ jobs:
- run: pnpm install
- run: pnpm typecheck
- run: pnpm test
- name: Build templates
run: pnpm run build

- name: Install uv
uses: astral-sh/setup-uv@v3
with:
version: '0.4.27'
- name: Gen APKG
run: pnpm run package

- name: Create Release Pull Request or Tag
id: changesets
Expand All @@ -34,19 +43,6 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Build templates
if: steps.changesets.outputs.published == 'true'
run: pnpm run build

- name: Install uv
if: steps.changesets.outputs.published == 'true'
uses: astral-sh/setup-uv@v3
with:
version: '0.4.27'
- name: Gen APKG
if: steps.changesets.outputs.published == 'true'
run: pnpm run package

- name: Release
if: steps.changesets.outputs.published == 'true'
uses: ncipollo/[email protected]
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ For the directly usable version, please download it from the [release](https://g

> [!TIP]
> Each template has multiple variants available for download, with the filename format being `{template}.{locale}.{field}.apkg`
>
> Be sure to read the specific instructions and tips for each template below before use

```
template:
Expand Down Expand Up @@ -52,6 +54,7 @@ Note: When all options are empty, the template will behave as a basic Q&A templa
| optionA...F | This is the content of the question options. Options that are not filled in will not be displayed, and various formats are also supported. |
| answer | This is the answer to the question. For multiple-choice questions, please write the uppercase letter of the correct answer, for example, A. For multiple-choice questions, write all the correct answer letters, such as ABC. |
| note | You can fill in detailed explanations, notes, etc., here. |
| noteA...F | You can fill in detailed explanations, notes for every option |

### Match

Expand Down
20 changes: 20 additions & 0 deletions build/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ const mcq = defineEntry({
'optionF',
'answer',
'note',
'noteA',
'noteB',
'noteC',
'noteD',
'noteE',
'noteF',
'Tags',
],
notes: [
Expand All @@ -45,6 +51,8 @@ const mcq = defineEntry({
optionC: 'And various formats are also supported.',
answer: 'AC',
note: 'Above is the answer to the question. For multiple-choice questions, please write the uppercase letter of the correct answer, for example, A. For multiple-choice questions, write all the correct answer letters, such as ABC.',
noteA: 'Note for optionA',
noteC: 'Note for optionC',
},
},
{
Expand All @@ -58,6 +66,8 @@ const mcq = defineEntry({
optionC: 'And various formats are also supported.',
answer: 'AC',
note: 'Above is the answer to the question. For multiple-choice questions, please write the uppercase letter of the correct answer, for example, A. For multiple-choice questions, write all the correct answer letters, such as ABC.',
noteA: 'Note for optionA',
noteC: 'Note for optionC',
},
},
],
Expand All @@ -78,6 +88,16 @@ const mcq_10 = defineEntry({
'optionJ',
'answer',
'note',
'noteA',
'noteB',
'noteC',
'noteD',
'noteE',
'noteF',
'noteG',
'noteH',
'noteI',
'noteJ',
'Tags',
],
notes: mcq.notes,
Expand Down
55 changes: 31 additions & 24 deletions src/entries/mcq.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,15 @@ export default () => {
() => (getFieldText('answer') || '').split('').map((c) => `option${c}`),
[],
);
const [originOptions, shuffledOptions] = useCreation(() => {
const [originOptions, shuffledOptions, notedOptions] = useCreation(() => {
const options = fields.filter(
(name) => name.startsWith('option') && !isFieldEmpty(FIELD_ID(name)),
);
const notedOptions = options.filter(
(name) => !isFieldEmpty(FIELD_ID(`note${name.slice('option'.length)}`)),
);

return [options, shuffle(options)] as const;
return [options, shuffle(options), notedOptions] as const;
}, []);
const [options, setOptions] = useCrossState(
'options-array',
Expand Down Expand Up @@ -128,7 +131,10 @@ export default () => {
questionExtra={
options.length ? (
<div
className={clsx('mt-5', prefBiggerText ? 'prose-xl' : '')}
className={clsx(
'mt-5 space-y-3 lg:space-y-6',
prefBiggerText ? 'prose-xl' : '',
)}
ref={parent}
onClick={() => setBlurred(false)}
>
Expand All @@ -139,10 +145,10 @@ export default () => {
key={name}
onClick={() => onClick(name)}
className={clsx(
'select-type-hint relative mb-3 cursor-pointer transition-transform before:select-none after:select-none last:mb-0 lg:mb-6',
'select-type-hint relative cursor-pointer transition-transform before:select-none after:select-none',
{
'active:scale-95': !back,
'after:absolute after:left-px after:top-0 after:block after:-translate-x-full after:rounded-l after:px-0.5 after:py-1 after:text-xs after:text-white':
'after:absolute after:left-0 after:top-[-2px] after:block after:-translate-x-full after:rounded-l after:px-0.5 after:py-1 after:text-xs after:text-white':
selectResult !== 'none',
'after:origin-top-right after:scale-75':
selectResult !== 'none' &&
Expand All @@ -163,7 +169,7 @@ export default () => {
[clsx(
`before:absolute before:content-['${fieldToAlpha(
name,
)}'] before:-top-4 before:right-1 before:text-4xl before:font-extrabold before:italic before:opacity-20`,
)}'] before:-top-5 before:right-1 before:text-4xl before:font-extrabold before:italic before:opacity-20`,
'dark:before:opacity-50',
)]: back,
'before:text-indigo-500 after:hidden':
Expand All @@ -172,26 +178,27 @@ export default () => {
{
[`pointer-events-none blur`]: blurred,
},
'rounded-xl border-2 border-transparent bg-indigo-50 px-4 py-2 transition-colors',
{
'!border-indigo-500 !bg-indigo-50':
!back && isSelected(name),
'!border-red-500 !bg-red-50': selectResult === 'wrong',
'!border-green-500 !bg-green-50':
selectResult === 'correct',
'!border-amber-500 !bg-amber-50':
selectResult === 'missed',
'!rounded-tl-none': selectResult !== 'none',
},
'dark:!bg-opacity-10',
)}
>
<AnkiField
name={name}
className={clsx(
'rounded-xl border-2 border-transparent bg-indigo-50 px-4 py-2 transition-colors',
{
'!border-indigo-500 !bg-indigo-50 !text-indigo-500':
!back && isSelected(name),
'!border-red-500 !bg-red-50 !text-red-500':
selectResult === 'wrong',
'!border-green-500 !bg-green-50 !text-green-500':
selectResult === 'correct',
'!border-amber-500 !bg-amber-50 !text-amber-500':
selectResult === 'missed',
'!rounded-tl-none': selectResult !== 'none',
},
'dark:!bg-opacity-10',
)}
/>
<AnkiField name={name} />
{back && notedOptions.includes(name) ? (
<AnkiField
name={`note${name.slice('option'.length)}`}
className="prose-sm border-t mt-2"
/>
) : null}
</div>
);
})}
Expand Down