From e0334cfbabc0c59efbd7349c58ef3188143b1f30 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Thu, 11 Jun 2020 00:01:44 +0200 Subject: [PATCH] Fix some bugs --- jishoScrape/index.js | 2 +- jishoScrape/src/chapterTabular.js | 11 +++++++---- jishoScrape/src/texConversion.js | 11 +++++++---- kanjiLib.tex | 2 ++ main.tex | 12 ++++++------ 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/jishoScrape/index.js b/jishoScrape/index.js index 02e6415..4a9b47e 100644 --- a/jishoScrape/index.js +++ b/jishoScrape/index.js @@ -18,7 +18,7 @@ async function main(grade) { const kanjiArray = jishoResults.map(result => result.query); log('Generating tex pages'); - const texData = getKanjiTexData(jishoResults); + const texData = getKanjiTexData(jishoResults, grade); log('Generating chapter table page'); const chapterTable = chapterTabular(kanjiArray, 16); diff --git a/jishoScrape/src/chapterTabular.js b/jishoScrape/src/chapterTabular.js index 14a6994..09345f8 100644 --- a/jishoScrape/src/chapterTabular.js +++ b/jishoScrape/src/chapterTabular.js @@ -1,9 +1,12 @@ function makeNumberRow(rowLength) { - let numberRow = [...Array(rowLength).keys()]; // Array containing numbers 0 to rowLength -1 + let numberRow = [...Array(rowLength).keys()]; // Array containing numbers 0 to rowLength-1 numberRow = numberRow.map((number) => (number + 1).toString()); // Correct numbers and convert to string numberRow = numberRow.map((number) => `{\\large ${number}}`); // Encapsulate numbers in TeX code numberRow = [' ', ...numberRow]; - return `${numberRow.join(' & ')} \\\\\n\\hline\n\\endhead\n`; + return ` + ${numberRow.join(' & ')} \\\\ + \\hline + \\endhead\n`; } function kanjiRow(index, rowLength, kanjiArray) { @@ -25,7 +28,7 @@ function makeRows(rowLength, columnLength, kanjiArray) { line.push(`{\\large ${index}}`); // Concatenate the number with the rest of the row - line = [line, kanjiRow(index, rowLength, kanjiArray)]; + line = [...line, ...kanjiRow(index, rowLength, kanjiArray)]; // Convert the line array into a tex row and add it to result. result += `${line.join(' & ')} \\\\\n`; @@ -48,7 +51,7 @@ function chapterTabular(kanjiArray, rowLength) { tabularString += makeNumberRow(rowLength); tabularString += makeRows(rowLength, columnLength, kanjiArray); - return `\\begin{chapterTabular}{ ${'l | ' + 'l '.repeat(rowLength)}} + return `\\begin{chapterTabular}{ ${' l | ' + 'l '.repeat(rowLength)}} ${tabularString}\\end{chapterTabular}` } diff --git a/jishoScrape/src/texConversion.js b/jishoScrape/src/texConversion.js index d386bb0..fa093da 100644 --- a/jishoScrape/src/texConversion.js +++ b/jishoScrape/src/texConversion.js @@ -5,7 +5,7 @@ const stylingBrackets = { const yomiConnector = '、 '; const yomiDash = '—'; -const styleText = (string) => stylingBrackets.start + string + stylingBrackets.end; +const styleText = (string) => `\\emphasize{${string}}`; function styleCharactersBeforeDot(string) { const words = string.split('.'); @@ -80,19 +80,22 @@ const makeFirstLetterUppercase = (string) => string.charAt(0).toUpperCase() + st /** * Generate TeX strings from Jisho data * @param {object[]} jishoResults Array of results fetched from Jisho + * @param {string} grade * @returns {object} An object containg TeX strings */ -function getKanjiTexData(jishoResults) { +function getKanjiTexData(jishoResults, grade) { return jishoResults.map(jishoResult => { const meaning = convertMeaning(jishoResult); const kunyomi = convertKunyomi(jishoResult); const onyomi = convertOnyomi(jishoResult); - jishoResult.taughtIn = jishoResult.taughtIn ? makeFirstLetterUppercase(jishoResult.taughtIn) : ''; + grade = grade.slice(0,5) + ' ' + grade.slice(5); + grade = makeFirstLetterUppercase(grade); + if (grade === 'Grade 7') grade = 'Junior high' return { - kanjiPageHeader: `\\kanjiPageHeader{${jishoResult.query}}{${jishoResult.taughtIn}}{${jishoResult.jlptLevel}}{${jishoResult.strokeCount}}{${jishoResult.radical.symbol}}`, + kanjiPageHeader: `\\kanjiPageHeader{${jishoResult.query}}{${grade}}{${jishoResult.jlptLevel}}{${jishoResult.strokeCount}}{${jishoResult.radical.symbol}}`, kanjiMeaning: meaning ? `\\kanjiMeaning{${meaning}}` : '', kunyomi: kunyomi ? `\\kunyomi{${kunyomi}}` : '', onyomi: onyomi ? `\\onyomi{${onyomi}}` : '', diff --git a/kanjiLib.tex b/kanjiLib.tex index 74e98d6..f180036 100644 --- a/kanjiLib.tex +++ b/kanjiLib.tex @@ -135,6 +135,8 @@ % Kunyomi and Onyomi % % ---------------------------------------------------------------------------- % +\newcommand{\emphasize}[1]{\textbf{\textcolor{kanjiColor!80!black}{#1}}} + \newtcolorbox{kunyomiBox}{ enhanced, attach boxed title to top left={yshift=-12pt,xshift=10pt}, diff --git a/main.tex b/main.tex index a2aba98..95cc424 100644 --- a/main.tex +++ b/main.tex @@ -60,21 +60,21 @@ \input{./data/pages/grade1.tex} \chapterIntroduction{Grade 2}{grade2} - \input{./data/pages/grade2.tex} + % \input{./data/pages/grade2.tex} \chapterIntroduction{Grade 3}{grade3} - \input{./data/pages/grade3.tex} + % \input{./data/pages/grade3.tex} \chapterIntroduction{Grade 4}{grade4} - \input{./data/pages/grade4.tex} + % \input{./data/pages/grade4.tex} \chapterIntroduction{Grade 5}{grade5} - \input{./data/pages/grade5.tex} + % \input{./data/pages/grade5.tex} \chapterIntroduction{Grade 6}{grade6} - \input{./data/pages/grade6.tex} + % \input{./data/pages/grade6.tex} \chapterIntroduction{Junior High}{grade7} - \input{./data/pages/grade7.tex} + % \input{./data/pages/grade7.tex} \end{document} \ No newline at end of file