Улучшил парсинг имени автора из fb2

This commit is contained in:
Book Pauk
2019-03-15 11:27:34 +07:00
parent cd5d3903fe
commit 37d60bc9b9
3 changed files with 38 additions and 14 deletions

View File

@@ -164,11 +164,21 @@ class HistoryPage extends Vue {
else
title = '';
let author = _.compact([
fb2.lastName,
fb2.firstName,
fb2.middleName
]).join(' ');
let author = '';
if (fb2.author) {
const authorNames = fb2.author.map(a => _.compact([
a.lastName,
a.firstName,
a.middleName
]).join(' '));
author = authorNames.join(', ');
} else {
author = _.compact([
fb2.lastName,
fb2.firstName,
fb2.middleName
]).join(' ');
}
author = (author ? author : (fb2.bookTitle ? fb2.bookTitle : book.url));
result.push({

View File

@@ -377,13 +377,17 @@ class TextPage extends Vue {
this.meta = bookManager.metaOnly(this.book);
this.fb2 = this.meta.fb2;
const authorName = _.compact([
this.fb2.lastName,
this.fb2.firstName,
this.fb2.middleName
]).join(' ');
let authorNames = [];
if (this.fb2.author) {
authorNames = this.fb2.author.map(a => _.compact([
a.lastName,
a.firstName,
a.middleName
]).join(' '));
}
this.title = _.compact([
authorName,
authorNames.join(', '),
this.fb2.bookTitle
]).join(' - ');

View File

@@ -201,6 +201,12 @@ export default class BookParser {
}
}
if (elemName == 'author' && path.indexOf('/fictionbook/description/title-info/author') == 0) {
if (!fb2.author)
fb2.author = [];
fb2.author.push({});
}
if (path.indexOf('/fictionbook/body') == 0) {
if (tag == 'body') {
if (!isFirstBody)
@@ -319,15 +325,19 @@ export default class BookParser {
text = text.replace(/[\t\n\r\xa0]/g, ' ');
const authorLength = (fb2.author && fb2.author.length ? fb2.author.length : 0);
switch (path) {
case '/fictionbook/description/title-info/author/first-name':
fb2.firstName = text;
if (authorLength)
fb2.author[authorLength - 1].firstName = text;
break;
case '/fictionbook/description/title-info/author/middle-name':
fb2.middleName = text;
if (authorLength)
fb2.author[authorLength - 1].middleName = text;
break;
case '/fictionbook/description/title-info/author/last-name':
fb2.lastName = text;
if (authorLength)
fb2.author[authorLength - 1].lastName = text;
break;
case '/fictionbook/description/title-info/genre':
fb2.genre = text;