add meaning to sentence cloze

This commit is contained in:
polv committed 2022-05-01 19:52:28 +07:00
1 parent b4bc954057
commit cfadfd60a7
1 file changed
+24 -4
+24 -4
View File
@@ -433,6 +433,7 @@ export class WaniKani {
ja: string; ja: string;
en: string; en: string;
}[]; }[];
meaning: string;
} }
>(); >();
vocabularies.map((v) => { vocabularies.map((v) => {
@@ -442,6 +443,10 @@ export class WaniKani {
sentenceMap.set(v.data.characters, { sentenceMap.set(v.data.characters, {
...sent, ...sent,
sentences: v.data.context_sentences, sentences: v.data.context_sentences,
meaning: v.data.meanings
.sort((m1, m2) => Number(m2.primary) - Number(m1.primary))
.map((m) => m.meaning)
.join('; '),
}); });
}); });
if (!sentenceMap.size) return; if (!sentenceMap.size) return;
@@ -476,10 +481,10 @@ export class WaniKani {
[fields.sentenceEn]: sent.en, [fields.sentenceEn]: sent.en,
}; };
if ( if (fields.sentenceCloze) {
fields.sentenceCloze && let clozeSent = n.fields[fields.sentenceCloze]?.value || '';
!n.fields[fields.sentenceCloze]?.value
) { if (!clozeSent && sent.sentences.length) {
const clozeChar = '__'; const clozeChar = '__';
let newSent = sent.sentences let newSent = sent.sentences
.map(({ ja, en }) => `${ja}<br/>${en}`) .map(({ ja, en }) => `${ja}<br/>${en}`)
@@ -493,6 +498,21 @@ export class WaniKani {
}); });
fieldUpdate[fields.sentenceCloze] = newSent; fieldUpdate[fields.sentenceCloze] = newSent;
clozeSent = newSent;
}
const notJa = '[^\\p{sc=Han}\\p{sc=Katakana}\\p{sc=Hiragana}]+';
if (
clozeSent &&
!new RegExp(
`(^${notJa}<br/?>|<br/?><br/?>${notJa}$)`,
'u',
).test(clozeSent)
) {
fieldUpdate[fields.sentenceCloze] =
sent.meaning + '<br><br>' + clozeSent;
}
} }
notesToUpdate.push({ notesToUpdate.push({