Fix some bugs
This commit is contained in:
parent
1c7ffaebc3
commit
e0334cfbab
|
@ -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);
|
||||
|
|
|
@ -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}`
|
||||
}
|
||||
|
||||
|
|
|
@ -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}}` : '',
|
||||
|
|
|
@ -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},
|
||||
|
|
12
main.tex
12
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}
|
Loading…
Reference in New Issue