prototype subdeck from Kanji
This commit is contained in:
1 parent
1c362c0c1c
commit
f427a8e148
2 files changed
+56
-18
No files matched your search
+28
-6
@@ -1,6 +1,9 @@
|
||||
import { AnkiConnect } from '@/ankiconnect';
|
||||
|
||||
import { makeKanjiLevels } from './get-kanji-level';
|
||||
|
||||
const DECK = 'Takoboto';
|
||||
const KANJI_FIELD = 'Japanese';
|
||||
|
||||
async function main() {
|
||||
const anki = new AnkiConnect();
|
||||
@@ -11,7 +14,9 @@ async function main() {
|
||||
query: `deck:${DECK}`,
|
||||
})
|
||||
.then((cards) => anki.api('cardsInfo', { cards }))
|
||||
.then((rs) => {
|
||||
.then(async (rs) => {
|
||||
const kanjiLevels = await makeKanjiLevels();
|
||||
|
||||
const modelToSubdecks = new Map<
|
||||
string,
|
||||
{
|
||||
@@ -20,11 +25,28 @@ async function main() {
|
||||
>();
|
||||
rs.map((r) => {
|
||||
const vs = modelToSubdecks.get(r.modelName) || {};
|
||||
// Get the subdeck names from Kanji
|
||||
const subdeck = '???';
|
||||
vs[subdeck] = vs[subdeck] || [];
|
||||
vs[subdeck]!.push(r.cardId);
|
||||
modelToSubdecks.set(r.modelName, vs);
|
||||
const { value } = r.fields[KANJI_FIELD] || {};
|
||||
if (value) {
|
||||
// Get the subdeck names from Kanji
|
||||
let subdeck = '';
|
||||
let level = 0;
|
||||
|
||||
Array.from(value).map((k) => {
|
||||
const m = kanjiLevels.get(k);
|
||||
if (m && m.level > level) {
|
||||
level = m.level;
|
||||
subdeck = m.deckName;
|
||||
}
|
||||
});
|
||||
|
||||
if (subdeck) {
|
||||
const cardIds = vs[subdeck] || [];
|
||||
cardIds.push(r.cardId);
|
||||
vs[subdeck] = cardIds;
|
||||
|
||||
modelToSubdecks.set(r.modelName, vs);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return Promise.all(
|
||||
|
||||
Reference in new issue
Block a user