Skip to content

Commit

Permalink
Allow parsing book without chapters defined
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvire committed Nov 20, 2024
1 parent 6ec9f51 commit b6bd6e1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions config/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export type BookConfig = {
testament: string;
section: string; // Pentateuch
portions?: string;
chapters: number;
chaptersN: string; // 1-34
chapters?: number;
chaptersN?: string; // 1-34
fonts: string[];
file: string;
audio: BookCollectionAudioConfig[];
Expand Down
19 changes: 14 additions & 5 deletions convert/convertConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,14 +557,23 @@ function parseBookCollections(document: Document, verbose: number) {
const format = book.attributes.getNamedItem('format')?.value;
const file = book.getElementsByTagName('f')[0]?.innerHTML;

let chapters;
const chaptersTag = book.getElementsByTagName('ct')[0];
if (chaptersTag) {
chapters = parseInt(chaptersTag.attributes.getNamedItem('c')!.value);
}

let chaptersN;
const cnTag = book.getElementsByTagName('cn')[0];
if (cnTag) {
chaptersN = cnTag.attributes.getNamedItem('value')!.value;
}

books.push({
portions: book.getElementsByTagName('portions')[0]?.attributes.getNamedItem('value')
?.value,
chapters: parseInt(
book.getElementsByTagName('ct')[0].attributes.getNamedItem('c')!.value
),
chaptersN: book.getElementsByTagName('cn')[0].attributes.getNamedItem('value')!
.value,
chapters,
chaptersN,
fonts,
id: book.attributes.getNamedItem('id')!.value,
type: book.attributes.getNamedItem('type')?.value,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/data/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class NavigationContext {
await this.goto(
this.docSets[0],
collection.books[0].id,
collection.books[0].chaptersN.split('-')[0],
collection.books[0].chaptersN.split('-')[0], //TODO: what if chaptersN is undefined?
'1'
);
}
Expand Down

0 comments on commit b6bd6e1

Please sign in to comment.