From 7904d8727131f3f4d46dfa4e20cc04f77ad744b2 Mon Sep 17 00:00:00 2001 From: "Rasamoelina, Haja Onjatiana" <26148770+rhahao@users.noreply.github.com> Date: Mon, 6 Nov 2023 16:18:28 +0000 Subject: [PATCH 1/2] ignore epub files --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index cdc6a761..4fe49ef0 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ node_modules dist sample -.env \ No newline at end of file +.env + +*.epub \ No newline at end of file From e6ba3cc7e560eb3f839dd25c2175cdf15affd312 Mon Sep 17 00:00:00 2001 From: "Rasamoelina, Haja Onjatiana" <26148770+rhahao@users.noreply.github.com> Date: Mon, 6 Nov 2023 20:45:47 +0000 Subject: [PATCH 2/2] support mwb starting 202401 --- example/sample.js | 2 +- src/common/enhanced_parse_utils.js | 30 +--- src/common/epub_validation.js | 1 - src/common/html_utils.js | 64 +++++++- src/common/html_validation.js | 22 ++- src/common/language_rules.js | 51 ++----- src/common/parser.js | 42 +++--- src/common/parsing_rules.js | 229 +++-------------------------- src/locales/en/text.json | 40 ++--- 9 files changed, 149 insertions(+), 332 deletions(-) diff --git a/example/sample.js b/example/sample.js index 29745478..3a299669 100644 --- a/example/sample.js +++ b/example/sample.js @@ -204,13 +204,13 @@ export const fetchData = async (language, issue, pub) => { if (issue && pub) { const url = JW_CDN + new URLSearchParams({ langwritten: language, pub, output: 'json', issue }); + const res = await fetch(url); if (res.status === 200) { const result = await res.json(); const hasEPUB = result.files[language].EPUB; - const issueFetch = { issueDate: issue, currentYear: issue.substring(0, 4), language, hasEPUB: hasEPUB }; data = await fetchIssueData(issueFetch); diff --git a/src/common/enhanced_parse_utils.js b/src/common/enhanced_parse_utils.js index 43d843b6..984f61f7 100644 --- a/src/common/enhanced_parse_utils.js +++ b/src/common/enhanced_parse_utils.js @@ -1,13 +1,5 @@ import dateFormat from 'dateformat'; -import { - extractAYFAssignment, - extractCBSSource, - extractLCAssignment, - extractMonthName, - extractTGWBibleReading, - extractTGWTalk, - extractWTStudyDate, -} from './parsing_rules.js'; +import { extractMonthName, extractWTStudyDate } from './parsing_rules.js'; export const getMWBWeekDateEnhanced = (weekDate, mwbYear, lang) => { const { varDay, monthIndex } = extractMonthName(weekDate, lang); @@ -16,26 +8,6 @@ export const getMWBWeekDateEnhanced = (weekDate, mwbYear, lang) => { return dateFormat(schedDate, 'yyyy/mm/dd'); }; -export const getMWBTGWTalkEnhanced = (src, lang) => { - return extractTGWTalk(src, lang); -}; - -export const getMWBTGWBibleReadingEnhanced = (src, lang) => { - return extractTGWBibleReading(src, lang); -}; - -export const getMWBAYFEnhanced = (src, lang) => { - return extractAYFAssignment(src, lang); -}; - -export const getMWBLCEnhanced = (src, lang) => { - return extractLCAssignment(src, lang); -}; - -export const getMWBCBSEnhanced = (src, lang) => { - return extractCBSSource(src, lang); -}; - export const getWTStudyDateEnhanced = (src, lang) => { const { varDay, monthIndex, varYear } = extractWTStudyDate(src, lang); const schedDate = new Date(varYear, monthIndex, varDay); diff --git a/src/common/epub_validation.js b/src/common/epub_validation.js index 5c1b0613..7ffdb5e0 100644 --- a/src/common/epub_validation.js +++ b/src/common/epub_validation.js @@ -49,7 +49,6 @@ export const isValidEPUBIssue = (input) => { const issue = +epubFilename.split('_')[2].split('.epub')[0]; if (type === 'mwb' && issue < 202207) valid = false; - if (type === 'mwb' && issue >= 202401) valid = false; if (type === 'w' && issue < 202304) valid = false; return valid; diff --git a/src/common/html_utils.js b/src/common/html_utils.js index 7985a184..69816a61 100644 --- a/src/common/html_utils.js +++ b/src/common/html_utils.js @@ -16,26 +16,76 @@ export const getMWBWeeklyBibleReading = (htmlItem) => { }; export const getMWBAYFCount = (htmlItem) => { - return htmlItem.querySelector('#section3').querySelectorAll('li').length; + let count; + + const testSection = htmlItem.querySelector('#section3'); + + // pre-2024 mwb + if (testSection) { + count = testSection.querySelectorAll('li').length; + } + + // 2024 onward + if (!testSection) { + count = htmlItem.querySelectorAll('.du-color--gold-700').length - 1; + } + + return count; }; export const getMWBLCCount = (htmlItem) => { - const itemsCn = htmlItem.querySelector('#section4').querySelectorAll('li').length; - return itemsCn === 6 ? 2 : 1; + let count = 0; + + const testSection = htmlItem.querySelector('#section4'); + + // pre-2024 mwb + if (testSection) { + count = testSection.querySelectorAll('li').length; + count = count === 6 ? 2 : 1; + } + + // 2024 onward + if (testSection === null) { + count = htmlItem.querySelectorAll('h3.du-color--maroon-600').length - 1; + } + + return count; }; export const getMWBSources = (htmlItem) => { let src = ''; + // pre-2024 mwb // get elements with meeting schedule data: pGroup const pGroupData = htmlItem.querySelectorAll('.pGroup'); - pGroupData.forEach((pGroup) => { + for (const pGroup of pGroupData) { const liData = pGroup.querySelectorAll('li'); - liData.forEach((li) => { + for (const li of liData) { const firstP = li.querySelector('p'); src += '|' + firstP.textContent; - }); - }); + } + } + + // 2024 onward + // get elements with meeting schedule data: h3 + if (src.length === 0) { + const h3Texts = htmlItem.querySelectorAll('h3'); + + for (const h3 of h3Texts) { + src += '|' + h3.textContent; + const nextElement = h3.nextElementSibling; + if (nextElement) { + const tmp = nextElement.querySelector('.du-color--textSubdued'); + if (tmp) { + const firstP = tmp.querySelector('p'); + src += ' ' + firstP.textContent; + } + } + } + + const sepBeforeBR = src.split('|', 5).join('|').length; + src = src.substring(0, sepBeforeBR) + '|junk|junk' + src.substring(sepBeforeBR); + } src = src.replaceAll(/\u00A0/g, ' '); // remove non-breaking space diff --git a/src/common/html_validation.js b/src/common/html_validation.js index 048edb70..cf2f3c40 100644 --- a/src/common/html_validation.js +++ b/src/common/html_validation.js @@ -20,10 +20,26 @@ export const getHTMLString = async (zip, filename) => { export const isValidMWBSchedule = (htmlDoc) => { let valid = false; + let isValidTGW = false; + let isValidAYF = false; + let isValidLC = false; - const isValidTGW = htmlDoc.querySelector(`[class*=treasures]`) ? true : false; - const isValidAYF = htmlDoc.querySelector(`[class*=ministry]`) ? true : false; - const isValidLC = htmlDoc.querySelector(`[class*=christianLiving]`) ? true : false; + // pre-2024 mwb + + isValidTGW = htmlDoc.querySelector(`[class*=treasures]`) ? true : false; + if (isValidTGW) { + isValidAYF = htmlDoc.querySelector(`[class*=ministry]`) ? true : false; + isValidLC = htmlDoc.querySelector(`[class*=christianLiving]`) ? true : false; + } + + // 2024 onward + if (!isValidTGW) { + isValidTGW = htmlDoc.querySelector('.du-color--teal-700') ? true : false; + if (isValidTGW) { + isValidAYF = htmlDoc.querySelector('.du-color--gold-700') ? true : false; + isValidLC = htmlDoc.querySelector('.du-color--maroon-600') ? true : false; + } + } if (isValidTGW === true && isValidAYF === true && isValidLC === true) { valid = true; diff --git a/src/common/language_rules.js b/src/common/language_rules.js index 08713a84..c5b1f552 100644 --- a/src/common/language_rules.js +++ b/src/common/language_rules.js @@ -1,43 +1,24 @@ const languages = window.jw_epub_parser.languages; export const getMonthNames = (lang) => { - return [ - { index: 0, name: languages[lang].januaryVariations }, - { index: 1, name: languages[lang].februaryVariations }, - { index: 2, name: languages[lang].marchVariations }, - { index: 3, name: languages[lang].aprilVariations }, - { index: 4, name: languages[lang].mayVariations }, - { index: 5, name: languages[lang].juneVariations }, - { index: 6, name: languages[lang].julyVariations }, - { index: 7, name: languages[lang].augustVariations }, - { index: 8, name: languages[lang].septemberVariations }, - { index: 9, name: languages[lang].octoberVariations }, - { index: 10, name: languages[lang].novemberVariations }, - { index: 11, name: languages[lang].decemberVariations }, - ]; + return [ + { index: 0, name: languages[lang].januaryVariations }, + { index: 1, name: languages[lang].februaryVariations }, + { index: 2, name: languages[lang].marchVariations }, + { index: 3, name: languages[lang].aprilVariations }, + { index: 4, name: languages[lang].mayVariations }, + { index: 5, name: languages[lang].juneVariations }, + { index: 6, name: languages[lang].julyVariations }, + { index: 7, name: languages[lang].augustVariations }, + { index: 8, name: languages[lang].septemberVariations }, + { index: 9, name: languages[lang].octoberVariations }, + { index: 10, name: languages[lang].novemberVariations }, + { index: 11, name: languages[lang].decemberVariations }, + ]; }; -export const getTGWTalkVariations = (lang) => languages[lang].tgwTalk10Variations; - -export const getTGWBibleReadingVariations = (lang) => languages[lang].tgwBibleReadingVariations; - -export const getAssignmentsName = (lang) => [ - languages[lang].initialCallVideoVariations, - languages[lang].returnVisitVideoVariations, - languages[lang].memorialInvitationVideoVariations, - languages[lang].initialCallVariations, - languages[lang].returnVisitVariations, - languages[lang].bibleStudyVariations, - languages[lang].talkVariations, - languages[lang].memorialInvitationVariations, -]; - -export const getAssignmentsVariations = (lang) => languages[lang].assignmentAyfVariations; - -export const getLivingPartsVariations = (lang) => languages[lang].assignmentLcVariations; - -export const getCBSVariations = (lang) => languages[lang].cbsVariations; - export const getConcludingSongFormat = (lang) => languages[lang].concludingSongVariations; export const getStudyArticleDateVariations = (lang) => languages[lang].studyArticleDateVariations; + +export const getPartMinutesSeparatorVariations = (lang) => languages[lang].partMinutesSeparatorVariations; diff --git a/src/common/parser.js b/src/common/parser.js index 3f44787f..4ec36c6e 100644 --- a/src/common/parser.js +++ b/src/common/parser.js @@ -1,13 +1,5 @@ import languages from '../locales/languages.js'; -import { - getMWBAYFEnhanced, - getMWBCBSEnhanced, - getMWBLCEnhanced, - getMWBTGWBibleReadingEnhanced, - getMWBTGWTalkEnhanced, - getMWBWeekDateEnhanced, - getWTStudyDateEnhanced, -} from './enhanced_parse_utils.js'; +import { getMWBWeekDateEnhanced, getWTStudyDateEnhanced } from './enhanced_parse_utils.js'; import { extractEPUBFiles, getHTMLDocs, validateEPUBContents } from './epub_jszip.js'; import { getEPUBData, @@ -30,7 +22,7 @@ import { getWStudyDate, getWStudyTitle, } from './html_utils.js'; -import { extractLastSong, extractSongNumber } from './parsing_rules.js'; +import { extractLastSong, extractSongNumber, extractSourceEnhanced } from './parsing_rules.js'; export const startParse = async (epubInput) => { let result = {}; @@ -128,7 +120,7 @@ export const parseMWBSchedule = (htmlItem, mwbYear, mwbLang) => { // 10min TGW Source tmpSrc = splits[3].trim(); if (isEnhancedParsing) { - weekItem.mwb_tgw_talk = getMWBTGWTalkEnhanced(tmpSrc, mwbLang); + weekItem.mwb_tgw_talk = extractSourceEnhanced(tmpSrc, mwbLang).type; } else { weekItem.mwb_tgw_talk = tmpSrc; } @@ -136,7 +128,7 @@ export const parseMWBSchedule = (htmlItem, mwbYear, mwbLang) => { //Bible Reading Source tmpSrc = splits[7].trim(); if (isEnhancedParsing) { - weekItem.mwb_tgw_bread = getMWBTGWBibleReadingEnhanced(tmpSrc, mwbLang); + weekItem.mwb_tgw_bread = extractSourceEnhanced(tmpSrc, mwbLang).src; } else { weekItem.mwb_tgw_bread = tmpSrc; } @@ -150,7 +142,7 @@ export const parseMWBSchedule = (htmlItem, mwbYear, mwbLang) => { //AYF1 Source tmpSrc = splits[8].trim(); if (isEnhancedParsing) { - const partEnhanced = getMWBAYFEnhanced(tmpSrc, mwbLang); + const partEnhanced = extractSourceEnhanced(tmpSrc, mwbLang); weekItem.mwb_ayf_part1 = partEnhanced.src; weekItem.mwb_ayf_part1_time = partEnhanced.time; weekItem.mwb_ayf_part1_type = partEnhanced.type; @@ -162,7 +154,7 @@ export const parseMWBSchedule = (htmlItem, mwbYear, mwbLang) => { if (cnAYF > 1) { tmpSrc = splits[9].trim(); if (isEnhancedParsing) { - const partEnhanced = getMWBAYFEnhanced(tmpSrc, mwbLang); + const partEnhanced = extractSourceEnhanced(tmpSrc, mwbLang); weekItem.mwb_ayf_part2 = partEnhanced.src; weekItem.mwb_ayf_part2_time = partEnhanced.time; weekItem.mwb_ayf_part2_type = partEnhanced.type; @@ -175,7 +167,7 @@ export const parseMWBSchedule = (htmlItem, mwbYear, mwbLang) => { if (cnAYF > 2) { tmpSrc = splits[10].trim(); if (isEnhancedParsing) { - const partEnhanced = getMWBAYFEnhanced(tmpSrc, mwbLang); + const partEnhanced = extractSourceEnhanced(tmpSrc, mwbLang); weekItem.mwb_ayf_part3 = partEnhanced.src; weekItem.mwb_ayf_part3_time = partEnhanced.time; weekItem.mwb_ayf_part3_type = partEnhanced.type; @@ -188,7 +180,7 @@ export const parseMWBSchedule = (htmlItem, mwbYear, mwbLang) => { if (cnAYF > 3) { tmpSrc = splits[11].trim(); if (isEnhancedParsing) { - const partEnhanced = getMWBAYFEnhanced(tmpSrc, mwbLang); + const partEnhanced = extractSourceEnhanced(tmpSrc, mwbLang); weekItem.mwb_ayf_part4 = partEnhanced.src; weekItem.mwb_ayf_part4_time = partEnhanced.time; weekItem.mwb_ayf_part4_type = partEnhanced.type; @@ -212,11 +204,11 @@ export const parseMWBSchedule = (htmlItem, mwbYear, mwbLang) => { tmpSrc = splits[nextIndex].trim(); if (isEnhancedParsing) { - const lcEnhanced = getMWBLCEnhanced(tmpSrc, mwbLang); - weekItem.mwb_lc_part1 = lcEnhanced.title; + const lcEnhanced = extractSourceEnhanced(tmpSrc, mwbLang); + weekItem.mwb_lc_part1 = lcEnhanced.type; weekItem.mwb_lc_part1_time = lcEnhanced.time; - if (lcEnhanced.content && lcEnhanced.content !== '') { - weekItem.mwb_lc_part1_content = lcEnhanced.content; + if (lcEnhanced.src && lcEnhanced.src !== '') { + weekItem.mwb_lc_part1_content = lcEnhanced.src; } } else { weekItem.mwb_lc_part1 = tmpSrc; @@ -228,11 +220,11 @@ export const parseMWBSchedule = (htmlItem, mwbYear, mwbLang) => { tmpSrc = splits[nextIndex].trim(); if (isEnhancedParsing) { - const lcEnhanced = getMWBLCEnhanced(tmpSrc, mwbLang); - weekItem.mwb_lc_part2 = lcEnhanced.title; + const lcEnhanced = extractSourceEnhanced(tmpSrc, mwbLang); + weekItem.mwb_lc_part2 = lcEnhanced.type; weekItem.mwb_lc_part2_time = lcEnhanced.time; - if (lcEnhanced.content && lcEnhanced.content !== '') { - weekItem.mwb_lc_part2_content = lcEnhanced.content; + if (lcEnhanced.src && lcEnhanced.src !== '') { + weekItem.mwb_lc_part2_content = lcEnhanced.src; } } else { weekItem.mwb_lc_part2 = tmpSrc; @@ -244,7 +236,7 @@ export const parseMWBSchedule = (htmlItem, mwbYear, mwbLang) => { tmpSrc = splits[nextIndex].trim(); if (isEnhancedParsing) { - weekItem.mwb_lc_cbs = getMWBCBSEnhanced(tmpSrc, mwbLang); + weekItem.mwb_lc_cbs = extractSourceEnhanced(tmpSrc, mwbLang).src; } else { weekItem.mwb_lc_cbs = tmpSrc; } diff --git a/src/common/parsing_rules.js b/src/common/parsing_rules.js index bb48c429..3b8be426 100644 --- a/src/common/parsing_rules.js +++ b/src/common/parsing_rules.js @@ -1,14 +1,5 @@ import { JWEPUBParserError } from '../classes/error.js'; -import { - getAssignmentsName, - getAssignmentsVariations, - getCBSVariations, - getLivingPartsVariations, - getMonthNames, - getStudyArticleDateVariations, - getTGWBibleReadingVariations, - getTGWTalkVariations, -} from './language_rules.js'; +import { getMonthNames, getPartMinutesSeparatorVariations, getStudyArticleDateVariations } from './language_rules.js'; export const extractMonthName = (src, lang) => { let varDay; @@ -18,8 +9,8 @@ export const extractMonthName = (src, lang) => { for (const month of monthNames) { const monthLang = month.name; - const regex = new RegExp(`(${monthLang})`); - const array = regex.exec(src); + const regex = new RegExp(`(${monthLang.toLowerCase()})`); + const array = regex.exec(src.toLowerCase()); if (Array.isArray(array)) { varDay = +src.match(/(\d+)/)[0]; @@ -39,221 +30,49 @@ export const extractSongNumber = (src) => { return +src.match(/(\d+)/)[0]; }; -export const extractTGWTalk = (src, lang) => { - const variations = getTGWTalkVariations(lang).split('|'); - const pattern = '{{ title }}'; - - let result; - for (const variation of variations) { - const startIndex = variation.indexOf(pattern); - const endIndex = src.length - variation.replace(pattern, '').length + startIndex; - const extracted = src.substring(startIndex, endIndex); - const verifyExtract = variation.replace(pattern, extracted); - if (verifyExtract === src) { - result = extracted; - break; - } - } - - if (result) return result; - - throw new JWEPUBParserError('tgw-talk', `Parsing failed for Treasures from God’s Word part. The input was: ${src}`); -}; - -export const extractTGWBibleReading = (src, lang) => { - const variations = getTGWBibleReadingVariations(lang).split('|'); - const pattern = '{{ source }}'; - - let result; - for (const variation of variations) { - const startIndex = variation.indexOf(pattern); - const endIndex = src.length - variation.replace(pattern, '').length + startIndex; - const extracted = src.substring(startIndex, endIndex); - const verifyExtract = variation.replace(pattern, extracted); - if (verifyExtract === src) { - result = extracted; - break; - } - } - - if (result) return result; - - throw new JWEPUBParserError('tgw-bibleReading', `Parsing failed for Bible Reading part. The input was: ${src}`); -}; - -export const extractAYFAssignment = (src, lang) => { - const variations = getAssignmentsVariations(lang).split('|'); - const assignmentsName = getAssignmentsName(lang); - - const patternAssignment = '{{ assignment }}'; - const patternSource = '{{ source }}'; +export const extractSourceEnhanced = (src, lang) => { + const variations = getPartMinutesSeparatorVariations(lang).split('|'); let result; - for (const variation of variations) { - const patternSourceIndex = variation.indexOf(patternSource); - - const find = variation.substring(0, patternSourceIndex).trim(); - - let assignmentsList = '('; - for (let a = 0; a < assignmentsName.length; a++) { - let tmp = assignmentsName[a]; - tmp = tmp.replace('(', '\\('); - tmp = tmp.replace(')', '\\)'); - assignmentsList += tmp; - - if (a < assignmentsName.length - 1) { - assignmentsList += '|'; - } - } - assignmentsList += ')'; - - let textSearch = find.replace('{{ duration }}', '\\d+'); - textSearch = textSearch.replace('(', '\\('); - textSearch = textSearch.replace(')', '\\)'); - textSearch = textSearch.replace(') ', ') ?'); - textSearch = textSearch.replace('??', '?'); - textSearch = textSearch.replace(patternAssignment, assignmentsList); - - const regex = new RegExp(textSearch.trim()); - const array = regex.exec(src); - - if (array !== null) { - const partTiming = +array[0].match(/(\d+)/)[0]; - - let textSearch = find.replace('{{ assignment }}', ''); - textSearch = textSearch.replace('{{ duration }}', partTiming); - - const split = src.split(textSearch.trim()); - if (split.length === 2) { - const partType = split[0].trim(); - - let textSearch = variation.replace('{{ assignment }}', partType); - textSearch = textSearch.replace('{{ duration }}', partTiming); - - const findNextIndex = textSearch.indexOf('{{ source }}'); - const srcNext = src.substring(findNextIndex); - - const obj = { src: srcNext, type: partType, time: partTiming }; - - let verifyExtract = variation.replace('{{ assignment }}', obj.type); - verifyExtract = verifyExtract.replace('{{ duration }}', obj.time); - verifyExtract = verifyExtract.replace('{{ source }}', obj.src); - - if (verifyExtract === src) { - result = obj; - break; - } - } - } - } - - if (result) return result; - - throw new JWEPUBParserError( - 'ayf-part', - `Parsing failed for Apply Yourself to the Field Ministry part. The input was: ${src}` - ); -}; - -export const extractLCAssignment = (src, lang) => { - const variations = getLivingPartsVariations(lang).split('|'); - const patternSource = '{{ source }}'; - const patternDuration = '{{ duration }}'; - const patternContent = '{{ content }}'; - - let result; for (const variation of variations) { - const patternSourceIndex = variation.indexOf(patternSource); - const patternContentIndex = variation.indexOf(patternContent); - - let masterSearch = variation.replace(patternSource, ''); - masterSearch = masterSearch.replace(patternContent, ''); - - let textSearch = masterSearch.replace('{{ duration }}', '\\d+'); + let textSearch = variation.replace('{{ duration }}', '\\d+'); textSearch = textSearch.replace('(', '\\('); textSearch = textSearch.replace(')', '\\)'); - textSearch = textSearch.replace(':', ':?'); textSearch = textSearch.replace(') ', ') ?'); textSearch = textSearch.replace('??', '?'); const regex = new RegExp(textSearch.trim()); - const array = regex.exec(src); - - if (array !== null) { - const partTiming = +array[0].match(/(\d+)/)[0]; - const findStrings = masterSearch.replace(patternDuration, partTiming); + const match = src.match(regex); - let split = src.split(findStrings); + if (match) { + const splits = src.split(regex); + const duration = +match[0].match(/\d+/)[0]; - if (split.length === 1) { - split = src.split(findStrings.trim()); - } - - if (split.length === 2) { - let partTitle; - let partContent; - - if (split[1] === '') { - partTitle = split[0].trim(); - partContent = ''; - } + const tmpAssignment = splits[0].trim(); + const source = splits[1].trim(); - if (split[1] !== '') { - if (patternSourceIndex < patternContentIndex) { - partTitle = split[0].trim(); - partContent = split[1].trim(); - } + const indexSep = /\d+[\.-] /g; + const index = tmpAssignment.match(indexSep); + const assignmentSplits = tmpAssignment.split(indexSep); + let assignment; - if (patternSourceIndex > patternContentIndex) { - partTitle = split[1].trim(); - partContent = split[0].trim(); - } - } - - let verifyExtract = variation.replace('{{ source }}', partTitle); - verifyExtract = verifyExtract.replace('{{ duration }}', partTiming); - verifyExtract = verifyExtract.replace('{{ content }}', partContent); - - if (split[1] === '') verifyExtract = verifyExtract.trim(); - - if (verifyExtract === src) { - result = { - time: partTiming, - title: partTitle, - content: partContent, - }; - break; - } + if (index) { + assignment = assignmentSplits[1].trim(); + } else { + assignment = tmpAssignment; } - } - } - - if (result) return result; - - throw new JWEPUBParserError('lc-part', `Parsing failed for Living as Christians part. The input was: ${src}`); -}; - -export const extractCBSSource = (src, lang) => { - const variations = getCBSVariations(lang).split('|'); - const pattern = '{{ source }}'; + const regexColumn = /:$/; + assignment = assignment.replace(regexColumn, ''); - let result; - for (const variation of variations) { - const startIndex = variation.indexOf(pattern); - const endIndex = src.length - variation.replace('{{ source }}', '').length + startIndex; - const extracted = src.substring(startIndex, endIndex); - const verifyExtract = variation.replace('{{ source }}', extracted); - if (verifyExtract === src) { - result = extracted; - break; + result = { type: assignment, time: duration, src: source }; } } if (result) return result; - throw new JWEPUBParserError('lc-cbs', `Parsing failed for Congregation Bible Study part. The input was: ${src}`); + throw new JWEPUBParserError('jw-epub-parser', `Parsing failed. The input was: ${src}`); }; export const extractLastSong = (src) => { diff --git a/src/locales/en/text.json b/src/locales/en/text.json index 9e3d8485..a65ecd3f 100644 --- a/src/locales/en/text.json +++ b/src/locales/en/text.json @@ -1,28 +1,16 @@ { - "januaryVariations": "January", - "februaryVariations": "February", - "marchVariations": "March", - "aprilVariations": "April", - "mayVariations": "May", - "juneVariations": "June", - "julyVariations": "July", - "augustVariations": "August", - "septemberVariations": "September", - "octoberVariations": "October", - "novemberVariations": "November", - "decemberVariations": "December", - "tgwTalk10Variations": "{{ title }}: (10 min.)", - "tgwBibleReadingVariations": "Bible Reading: (4 min.) {{ source }}", - "initialCallVideoVariations": "Initial Call Video", - "returnVisitVideoVariations": "Return Visit Video", - "memorialInvitationVideoVariations": "Memorial Invitation Video", - "initialCallVariations": "Initial Call", - "returnVisitVariations": "Return Visit", - "bibleStudyVariations": "Bible Study", - "talkVariations": "Talk", - "memorialInvitationVariations": "Memorial Invitation", - "assignmentAyfVariations": "{{ assignment }}: ({{ duration }} min.) {{ source }}", - "assignmentLcVariations": "{{ source }}: ({{ duration }} min.)|{{ source }}: ({{ duration }} min.) {{ content }}", - "cbsVariations": "Congregation Bible Study: (30 min.) {{ source }}", - "studyArticleDateVariations": "Study Article {{ number }}: {{ date }}" + "januaryVariations": "January", + "februaryVariations": "February", + "marchVariations": "March", + "aprilVariations": "April", + "mayVariations": "May", + "juneVariations": "June", + "julyVariations": "July", + "augustVariations": "August", + "septemberVariations": "September", + "octoberVariations": "October", + "novemberVariations": "November", + "decemberVariations": "December", + "studyArticleDateVariations": "Study Article {{ number }}: {{ date }}", + "partMinutesSeparatorVariations": "({{ duration }} min.)" }