From e522777316c1bc696911afd34bab027c8472eacb Mon Sep 17 00:00:00 2001 From: StefanVukovic99 Date: Fri, 28 Jun 2024 18:40:37 +0200 Subject: [PATCH] use existing and custom css to color some tags (#91) * mvp * mvp * use existing name and archaism colors * update tests --- .gitignore | 2 ++ 4-make-yomitan.js | 26 +++++++++++++++++++ auto.sh | 6 +++-- .../en/tag_bank_term.json | 8 +++--- .../target-language-tags/en/tag_styles.json | 5 ++++ data/test/dict/de/en/tag_bank_1.json | 4 +-- 6 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 data/language/target-language-tags/en/tag_styles.json diff --git a/.gitignore b/.gitignore index adb0311..aef1c85 100755 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ !tag_bank_ipa.json !parts_of_speech.json !multiword_inflections.json +!tag_styles.json !tag_order.json !languages.json !package*.json @@ -13,6 +14,7 @@ !data/test/ipa/**/*.json *.zip +data/**/*.css *.txt !instructions.txt diff --git a/4-make-yomitan.js b/4-make-yomitan.js index 7b2e53e..04b84b3 100644 --- a/4-make-yomitan.js +++ b/4-make-yomitan.js @@ -46,6 +46,8 @@ const ipaTags = [...targetLanguageIpaTags, ...languageIpaTags]; const partsOfSpeech = loadJsonArray(`data/language/target-language-tags/${target_iso}/parts_of_speech.json`); const multiwordInflections = loadJsonArray(`data/language/${source_iso}/${target_iso}/multiword_inflections.json`); +const tagStylesFile = `data/language/target-language-tags/${target_iso}/tag_styles.json`; +const tagStyles = existsSync(tagStylesFile) ? JSON.parse(readFileSync(tagStylesFile)) : {}; const tagModifiers = [ ['chiefly', 'chief'], @@ -263,9 +265,18 @@ let lastTermBankIndex = 0; writeIndex('dict'); writeTags('dict'); + const dictTagStyles = getTagStyles('dict'); + if(dictTagStyles){ + writeStyles('dict', dictTagStyles); + } lastTermBankIndex = writeBanks('dict', ymtLemmas, lastTermBankIndex); writeIndex('ipa'); writeTags('ipa'); + const ipaTagStyles = getTagStyles('ipa'); + if(ipaTagStyles){ + writeStyles('ipa', ipaTagStyles); + } + writeBanks('ipa', ymtIpa); } @@ -427,6 +438,21 @@ function writeTags(folder) { writeFileSync(`${writeFolder}/${folder}/tag_bank_1.json`, JSON.stringify(Object.values(ymtTags[folder]))); } +function writeStyles(folder, tagStyles){ + writeFileSync(`${writeFolder}/${folder}/styles.css`, tagStyles); +} + +function getTagStyles(folder){ + let styles = ""; + for (const fullTag of Object.values(ymtTags[folder])) { + const tag = fullTag[0]; + if (tagStyles[tag]) { + styles += tagStyles[tag] + '\n'; + } + } + return styles; +} + function writeIndex(folder) { writeFileSync(`${writeFolder}/${folder}/index.json`, JSON.stringify({ ...indexJson, diff --git a/auto.sh b/auto.sh index 12611eb..4120156 100755 --- a/auto.sh +++ b/auto.sh @@ -152,6 +152,8 @@ for target_lang in "${languages[@]}"; do fi export temp_folder="data/temp" + temp_dict_folder="$temp_folder/dict" + temp_ipa_folder="$temp_folder/ipa" dict_file="${DICT_NAME}-$source_iso-$target_iso.zip" ipa_file="${DICT_NAME}-$source_iso-$target_iso-ipa.zip" @@ -163,8 +165,8 @@ for target_lang in "${languages[@]}"; do echo "Creating Yomitan dict and IPA files" if node --max-old-space-size="$max_memory_mb" 4-make-yomitan.js; then echo "Zipping Yomitan files" - zip -qj "$dict_file" $temp_folder/dict/index.json $temp_folder/dict/tag_bank_1.json $temp_folder/dict/term_bank_*.json - zip -qj "$ipa_file" $temp_folder/ipa/index.json $temp_folder/ipa/tag_bank_1.json $temp_folder/ipa/term_meta_bank_*.json + zip -qj "$dict_file" $temp_dict_folder/index.json $temp_dict_folder/styles.css $temp_dict_folder/tag_bank_1.json $temp_dict_folder/term_bank_*.json + zip -qj "$ipa_file" $temp_ipa_folder/index.json $temp_ipa_folder/tag_bank_1.json $temp_ipa_folder/term_meta_bank_*.json else echo "Error: Yomitan generation script failed." fi diff --git a/data/language/target-language-tags/en/tag_bank_term.json b/data/language/target-language-tags/en/tag_bank_term.json index 15a9cc8..ff15b37 100755 --- a/data/language/target-language-tags/en/tag_bank_term.json +++ b/data/language/target-language-tags/en/tag_bank_term.json @@ -71,7 +71,7 @@ ], [ "name", - "partOfSpeech", + "name", -1, "name", 1 @@ -491,7 +491,7 @@ ], [ "arch", - "", + "archaism", 4, "archaic", -4 @@ -561,14 +561,14 @@ ], [ "dated", - "", + "archaism", 0, "dated", 0 ], [ "obs", - "", + "archaism", 0, "obsolete", 0 diff --git a/data/language/target-language-tags/en/tag_styles.json b/data/language/target-language-tags/en/tag_styles.json new file mode 100644 index 0000000..cf739b0 --- /dev/null +++ b/data/language/target-language-tags/en/tag_styles.json @@ -0,0 +1,5 @@ +{ + "masc": ".tag[data-details='masculine'] .tag-label{background-color: blue;}", + "fem": ".tag[data-details='feminine'] .tag-label{background-color: red;}", + "neut": ".tag[data-details='neuter'] .tag-label{background-color: green;}" +} \ No newline at end of file diff --git a/data/test/dict/de/en/tag_bank_1.json b/data/test/dict/de/en/tag_bank_1.json index e244210..0d01cd7 100644 --- a/data/test/dict/de/en/tag_bank_1.json +++ b/data/test/dict/de/en/tag_bank_1.json @@ -71,14 +71,14 @@ ], [ "arch", - "", + "archaism", 4, "archaic", -4 ], [ "obs", - "", + "archaism", 0, "obsolete", 0