Skip to content

Commit

Permalink
Check book filename matches assumption made in epub builds
Browse files Browse the repository at this point in the history
Epub builds assume books will be named <slug>.collection.xml
  • Loading branch information
TylerZeroMaster committed Jul 1, 2024
1 parent 77cc63d commit 30bf229
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion server/src/model/book.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import I from 'immutable'
import * as Quarx from 'quarx'
import { type PageNode } from './page'
import { type Opt, type WithRange, textWithRange, select, selectOne, findDuplicates, calculateElementPositions, expectValue, type HasRange, join, equalsOpt, equalsWithRange, tripleEq, equalsPos, equalsArray, PathKind, TocNodeKind } from './utils'
import { type Opt, type WithRange, textWithRange, select, selectOne, findDuplicates, calculateElementPositions, expectValue, type HasRange, join, equalsOpt, equalsWithRange, tripleEq, equalsPos, equalsArray, PathKind, TocNodeKind, NOWHERE } from './utils'
import { Fileish, type ValidationCheck, ValidationKind } from './fileish'
import { getCCLicense } from './cc-license'

Expand Down Expand Up @@ -157,12 +157,21 @@ export class BookNode extends Fileish {
message: BookValidationKind.DUPLICATE_PAGE,
nodesToLoad: I.Set(),
fn: () => I.Set(pageLeaves.filter(p => duplicatePages.has(p.page)).map(l => l.range))
},
{
message: BookValidationKind.INVALID_BOOK_NAME,
nodesToLoad: I.Set(),
fn: () => this.absPath.endsWith(`${this.slug}.collection.xml`)
? I.Set()
: I.Set([NOWHERE])
}
]
}
}

export class BookValidationKind extends ValidationKind {
// openstax/enki/bakery-js/src/epub/toc.tsx#L74
static INVALID_BOOK_NAME = new BookValidationKind('Book must be named <slug>.collection.xml')
static MISSING_PAGE = new BookValidationKind('Missing Page')
static DUPLICATE_CHAPTER_TITLE = new BookValidationKind('Duplicate chapter title')
static DUPLICATE_PAGE = new BookValidationKind('Duplicate page')
Expand Down
1 change: 1 addition & 0 deletions server/src/model/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export class Bundle extends Fileish implements Bundleish {
}

export class BundleValidationKind extends ValidationKind {
// openstax/enki/bakery-src/scripts/link_single.py#L59
static MISMATCHED_SLUG = new BundleValidationKind('Slug does not match any defined in a book')
static MISSING_BOOK = new BundleValidationKind('Missing book')
static NO_BOOKS = new BundleValidationKind('No books defined')
Expand Down

0 comments on commit 30bf229

Please sign in to comment.