Skip to content

Commit

Permalink
Separate out logic
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvNC committed Jan 20, 2024
1 parent d7b68a0 commit 8fd6842
Showing 1 changed file with 43 additions and 21 deletions.
64 changes: 43 additions & 21 deletions src/util/convertEntryToYomitanTerm.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,13 @@ function convertLanguageDataToSC(languageData, isExplanation) {
const languageLiScArray = [];

for (const language in languageData) {
const languageInfo = languages[language];
/**
* @type {string[]}
*/
const languageTexts = languageData[language];
for (const languageText of languageTexts) {
languageLiScArray.push({
tag: 'li',
lang: languageInfo.langCode,
style: {
listStyleType: `"(${
isExplanation ? languageInfo.name : languageInfo.shortName
})"`,
},
// TODO: use textParser function when built
content: languageText,
data: {
wordshk: languageInfo.langCode,
},
});
}
languageLiScArray.push(
...convertLanguageEntryToLi(
language,
languageData[language],
isExplanation
)
);
}

/**
Expand All @@ -65,3 +51,39 @@ function convertLanguageDataToSC(languageData, isExplanation) {

return sc;
}

/**
* Converts a single language entry to a li item
* @param {string} language
* @param {string[]} languageTexts
* @param {boolean} isExplanation
* @returns {import('yomichan-dict-builder/dist/types/yomitan/termbank').StructuredContent[]}
*/
function convertLanguageEntryToLi(language, languageTexts, isExplanation) {
/**
* @type {import('yomichan-dict-builder/dist/types/yomitan/termbank').StructuredContent[]}
*/
const languageLiScArray = [];
const languageInfo = languages[language];
/**
* @type {string[]}
*/
for (const languageText of languageTexts) {
languageLiScArray.push({
tag: 'li',
lang: languageInfo.langCode,
style: {
listStyleType: `"(${
isExplanation ? languageInfo.name : languageInfo.shortName
})"`,
},
// TODO: use textParser function when built
content: languageText,
data: {
wordshk: languageInfo.langCode,
},
});
}

return languageLiScArray;
}

0 comments on commit 8fd6842

Please sign in to comment.