From e543a541cd317704eda82ec213afd31af8b1ac2f Mon Sep 17 00:00:00 2001 From: Valentin Pratz Date: Fri, 20 Oct 2023 14:48:15 +0200 Subject: [PATCH] feat: add note type basic and reversed card This commit adds a boolean parameter `reversed` to the configuration. If the note type is not cloze and `reversed` is set to `true`, the note type will be set to "Basic (and reversed card)" instead of "Basic". As this is a standard note type, it should be available on all Anki installations. As the fields are identical to the Basic type, no unexpected problems should arise. --- sass/card.scss | 5 +++++ src/blueprints/basic-codeblock.ts | 1 + src/blueprints/sandwich.ts | 1 + src/entities/note.ts | 2 +- src/notes/base.ts | 6 +++++- 5 files changed, 13 insertions(+), 2 deletions(-) diff --git a/sass/card.scss b/sass/card.scss index f08d17d..db7dda7 100644 --- a/sass/card.scss +++ b/sass/card.scss @@ -91,6 +91,7 @@ div.ankibridge-card { // Boolean properties &[data-type="cloze"], + &[data-type="reversed"], &[data-type="enabled"], &[data-type="delete"] { font-size : 0; @@ -115,6 +116,10 @@ div.ankibridge-card { content: "Cloze"; } + &[data-type="reversed"]::before { + content: "Reversed Card"; + } + &[data-type="enabled"]::before { content: "Enabled:"; } diff --git a/src/blueprints/basic-codeblock.ts b/src/blueprints/basic-codeblock.ts index 4218e86..bbf71a3 100644 --- a/src/blueprints/basic-codeblock.ts +++ b/src/blueprints/basic-codeblock.ts @@ -39,6 +39,7 @@ export class BasicCodeBlockBlueprint extends CodeBlockBlueprint { delete: note.config.delete, enabled: note.config.enabled, cloze: note.config.cloze, + reversed: note.config.reversed, }) let str = '' diff --git a/src/blueprints/sandwich.ts b/src/blueprints/sandwich.ts index 68ac2ad..58b4870 100644 --- a/src/blueprints/sandwich.ts +++ b/src/blueprints/sandwich.ts @@ -30,6 +30,7 @@ export class SandwichBlueprint extends Blueprint { delete: note.config.delete, enabled: note.config.enabled, cloze: note.config.cloze, + reversed: note.config.reversed, }) let str = '' diff --git a/src/entities/note.ts b/src/entities/note.ts index ca8b1b6..bae1dda 100644 --- a/src/entities/note.ts +++ b/src/entities/note.ts @@ -14,7 +14,7 @@ export enum NoteField { } export type NoteFields = Record -export type ModelName = 'Basic' | 'Cloze' +export type ModelName = 'Basic' | 'Basic (and reversed card)' | 'Cloze' export interface SourceDescriptor { from: number diff --git a/src/notes/base.ts b/src/notes/base.ts index 19935aa..1d46bd9 100644 --- a/src/notes/base.ts +++ b/src/notes/base.ts @@ -20,6 +20,7 @@ export interface Config { delete?: boolean enabled?: boolean cloze?: boolean + reversed?: boolean } export interface ParseConfig extends Config { @@ -42,6 +43,7 @@ export const ParseConfigSchema: yup.SchemaOf = yup.object({ delete: yup.boolean().nullAsUndefined(), enabled: yup.boolean().nullAsUndefined(), cloze: yup.boolean().nullAsUndefined(), + reversed: yup.boolean().nullAsUndefined(), }) // Location @@ -154,7 +156,9 @@ export abstract class NoteBase { if (this.isCloze) { return 'Cloze' } - + else if (this.config.reversed) { + return 'Basic (and reversed card)' + } return 'Basic' }