Skip to content

Commit

Permalink
fix: Handle project name for filename regex
Browse files Browse the repository at this point in the history
  • Loading branch information
darcywong00 committed Sep 10, 2023
1 parent 4e019ac commit 684ac43
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/backTranslation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ export const VERSE_PATTERN = /(\d+)-?(\d+)?\s?(.*)/;
/**
* Extract a book name and chapter number from the filename
* @param {string} file - Path to the Toolbox text file
* @param {string} projectName - Name of the project (expected at the start of the filenames)
* @returns {fileInfoType} - Object containing the book name and chapter number
*/
export function getBookAndChapter(file: string) : toolbox.fileInfoType {
export function getBookAndChapter(file: string, projectName: string) : toolbox.fileInfoType {
const filename = path.parse(file).base;
const pattern = /(Lem|lem)?(\d*\D+)(\d+)\D?\.rtf/;
const patternFormatStr = `(${projectName}|${projectName.toLowerCase()})?(\\d*\\D+)(\\d+)\\D?\\.rtf`;
const pattern = new RegExp(patternFormatStr);
const match = filename.match(pattern);
const obj: toolbox.fileInfoType = {
bookName: "Placeholder",
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ function processDirectory(directory: string){
* @returns {books.bookType} bookObj - modified book object
*/
async function processBackText(filepath: string, bookObj: books.objType): Promise<books.objType> {
const bookInfo = backTranslation.getBookAndChapter(filepath);
const bookInfo = backTranslation.getBookAndChapter(filepath, options.projectName);
const currentChapter = bookInfo.chapterNumber;
const bookType = books.getBookByName(bookInfo.bookName);
if (bookInfo.bookName === "Placeholder") {
Expand Down

0 comments on commit 684ac43

Please sign in to comment.