Fix table bug, sort bug and path bug
This commit is contained in:
parent
8fe252ea48
commit
f6f5878164
|
@ -8,19 +8,20 @@ const {kanjiTable} = require('./src/kanjiTables.js');
|
|||
/* Encapsulate main process in async function */
|
||||
async function main(jlptLevel) {
|
||||
|
||||
const jlptLevelCaps = jlptLevel.toUpperCase();
|
||||
|
||||
const kanjiArray = await fetchKanjiFromTxt(`./data/txt/${jlptLevel}.txt`);
|
||||
console.log(`Fetched txt for ${jlptLevel}`);
|
||||
console.log(`${jlptLevelCaps}: Fetched txt`);
|
||||
|
||||
const results = await fetchKanjiFromJisho(kanjiArray);
|
||||
console.log(`Fetched data from Jisho for ${jlptLevel}`);
|
||||
console.log(`${jlptLevelCaps}: Fetched Jisho data`);
|
||||
|
||||
const sortedResults = sortKanji(results);
|
||||
const sortedKanji = sortedResults.map(result => result.query);
|
||||
const texData = getKanjiTexData(sortedResults);
|
||||
console.log(`Processed pages for ${jlptLevel}`);
|
||||
const sortedKanjiArray = results.map(result => result.query);
|
||||
const texData = getKanjiTexData(results);
|
||||
console.log(`${jlptLevelCaps}: Processed pages`);
|
||||
|
||||
const resultTable = kanjiTable(sortedKanji);
|
||||
console.log(`Processed table for ${jlptLevel}`);
|
||||
const resultTable = kanjiTable(sortedKanjiArray);
|
||||
console.log(`${jlptLevelCaps}: Processed table`);
|
||||
|
||||
let resultPage = '';
|
||||
for (kanji of texData) {
|
||||
|
@ -32,8 +33,8 @@ async function main(jlptLevel) {
|
|||
\\newpage\n`;
|
||||
}
|
||||
|
||||
fs.writeFile(`../data/tables/${jlptLevel}.tex`, resultTable, (err) => {if (err) console.error(err)});
|
||||
fs.writeFile(`../data/pages/${jlptLevel}.tex`, resultPage, (err) => {if (err) console.error(err)});
|
||||
fs.writeFile(`./data/tables/${jlptLevel}.tex`, resultTable, (err) => {if (err) console.error(err)});
|
||||
fs.writeFile(`./data/pages/${jlptLevel}.tex`, resultPage, (err) => {if (err) console.error(err)});
|
||||
}
|
||||
|
||||
async function mainWrapper() {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
function kanjiTable(kanjiArray) {
|
||||
const xLength = 20;
|
||||
const xLength = 15;
|
||||
const yLength = Math.ceil(kanjiArray.length/xLength);
|
||||
const sideLength = Math.ceil(Math.sqrt(kanjiArray.length));
|
||||
|
||||
|
@ -9,7 +9,7 @@ function kanjiTable(kanjiArray) {
|
|||
const lineArray = new Array;
|
||||
|
||||
for (let x_index = 0; x_index < xLength; x_index++) {
|
||||
const indexNumber = y_index * yLength + x_index;
|
||||
const indexNumber = y_index * xLength + x_index;
|
||||
lineArray.push(kanjiArray[indexNumber] ? kanjiArray[indexNumber] : '');
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue