Поправки дерева жанров

This commit is contained in:
Book Pauk
2022-09-12 16:15:30 +07:00
parent 75773a3e20
commit dd3685990b
2 changed files with 221 additions and 22 deletions

View File

@@ -1,13 +1,20 @@
const genresText = require('./genresText.js');
const genres = [];
const nonfb2Genres = [];//костылики
let nonfb2 = false;//костылики
const sec2index = {};
const lines = genresText.split('\n').map(l => l.trim());
let index = 0;
let other;//прочее в конец
const names = new Set();
for (const line of lines) {
if (line.indexOf('#nonfb2') == 0)
nonfb2 = true;
if (!line || line[0] == '#')
continue;
@@ -22,32 +29,49 @@ for (const line of lines) {
let name = line.substring(p + 1).trim();
if (num.length < 3) {//раздел
if (section == '0.20') {//прочее
other = {name, value: []};
} else {
if (sec2index[section] === undefined) {
if (!genres[index])
genres[index] = {name, value: []};
sec2index[section] = index;
index++;
if (!nonfb2) {
if (num.length < 3) {//раздел
if (section == '0.20') {//прочее
other = {name, value: []};
} else {
if (sec2index[section] === undefined) {
if (!genres[index])
genres[index] = {name, value: []};
sec2index[section] = index;
index++;
}
}
} else {//подраздел
const n = name.split(';').map(l => l.trim());
names.add(n[0]);
if (section == '0.20') {//прочее
other.value.push({name: n[1], value: n[0]});
} else {
const i = sec2index[section];
if (i !== undefined) {
genres[i].value.push({name: n[1], value: n[0]});
}
}
}
} else {//подраздел
} else {
const n = name.split(';').map(l => l.trim());
if (section == '0.20') {//прочее
other.value.push({name: n[1], value: n[0]});
} else {
const i = sec2index[section];
if (i !== undefined) {
genres[i].value.push({name: n[1], value: n[0]});
}
}
if (!names.has(n[0]))
nonfb2Genres.push({name: n[1], value: n[0]});
names.add(n[0]);
}
}
if (other)
if (other) {
if (nonfb2Genres.length) {
other.value = other.value.concat(nonfb2Genres);
}
genres.push(other);
}
//console.log(JSON.stringify(genres));
module.exports = genres;