Skip to content

Commit

Permalink
Check if example exist before adding nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvNC committed Jan 20, 2024
1 parent f541d8a commit 3e9bf49
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions src/util/yomitan/convertSenseToSC.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,32 @@ function convertSenseToLiSC(sense) {
phrases.push(eg);
}
}

/**
* @type {import('yomichan-dict-builder/dist/types/yomitan/termbank').StructuredContent[]}
*/
const exampleNodes = [];
if (phrases.length > 0) {
exampleNodes.push(
convertExampleToSC(
phrases,
'phrase',
examplePhraseText,
examplePhraseEmoji
)
);
}
if (sentences.length > 0) {
exampleNodes.push(
convertExampleToSC(
sentences,
'sentence',
exampleSentenceText,
exampleSentenceEmoji
)
);
}

return {
tag: 'li',
data: {
Expand All @@ -51,20 +77,7 @@ function convertSenseToLiSC(sense) {
data: {
wordshk: 'examples',
},
content: [
convertExampleToSC(
phrases,
'phrase',
examplePhraseText,
examplePhraseEmoji
),
convertExampleToSC(
sentences,
'sentence',
exampleSentenceText,
exampleSentenceEmoji
),
],
content: exampleNodes,
},
],
};
Expand Down

0 comments on commit 3e9bf49

Please sign in to comment.