update cloze maker
This commit is contained in:
1 parent
6d46308e78
commit
5cc5272f77
3 files changed
+115
-11
No files matched your search
+27
-8
@@ -413,6 +413,7 @@ export class WaniKani {
|
||||
sentenceJa: string;
|
||||
sentenceAudio?: string;
|
||||
sentenceEn: string;
|
||||
sentenceCloze?: string;
|
||||
},
|
||||
opts: {
|
||||
overwrite?: boolean;
|
||||
@@ -428,13 +429,20 @@ export class WaniKani {
|
||||
{
|
||||
ja: string;
|
||||
en: string;
|
||||
sentences: {
|
||||
ja: string;
|
||||
en: string;
|
||||
}[];
|
||||
}
|
||||
>();
|
||||
vocabularies.map((v) => {
|
||||
if (sentenceMap.has(v.data.characters)) return;
|
||||
const sent = v.data.context_sentences[0];
|
||||
if (!sent || !sent.ja.trim()) return;
|
||||
sentenceMap.set(v.data.characters, sent);
|
||||
sentenceMap.set(v.data.characters, {
|
||||
...sent,
|
||||
sentences: v.data.context_sentences,
|
||||
});
|
||||
});
|
||||
if (!sentenceMap.size) return;
|
||||
|
||||
@@ -459,16 +467,27 @@ export class WaniKani {
|
||||
for (const n of notes) {
|
||||
const { value: ja } = n.fields[fields.vocabJa] || {};
|
||||
if (ja) {
|
||||
const sent = sentenceMap.get(
|
||||
ja.replace(/\[.+?\]/g, '').replace(/ /g, ''),
|
||||
);
|
||||
const cleanJa = ja.replace(/\[.+?\]/g, '').replace(/ /g, '');
|
||||
const sent = sentenceMap.get(cleanJa);
|
||||
if (sent) {
|
||||
const fieldUpdate = {
|
||||
[fields.sentenceJa]: sent.ja,
|
||||
[fields.sentenceEn]: sent.en,
|
||||
};
|
||||
|
||||
if (
|
||||
fields.sentenceCloze &&
|
||||
!n.fields[fields.sentenceCloze]?.value
|
||||
) {
|
||||
fieldUpdate[fields.sentenceCloze] = sent.sentences
|
||||
.map(({ ja, en }) => `${ja}<br/>${en}`)
|
||||
.join('<br/>')
|
||||
.replace(cleanJa, '__');
|
||||
}
|
||||
|
||||
notesToUpdate.push({
|
||||
id: n.noteId,
|
||||
fields: {
|
||||
[fields.sentenceJa]: sent.ja,
|
||||
[fields.sentenceEn]: sent.en,
|
||||
},
|
||||
fields: fieldUpdate,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user