Skip to content

Commit

Permalink
fix(api): update logic to check schedule week date
Browse files Browse the repository at this point in the history
  • Loading branch information
rhahao committed Dec 19, 2023
1 parent 0175463 commit 2ad9482
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/common/html_validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { HTMLElement, parse } from 'node-html-parser';
export const isValidHTML = (name: string): boolean => {
let valid = false;

if (name.startsWith('OEBPS') && name.endsWith('.xhtml')) {
if (name.startsWith('OEBPS') && name.endsWith('.xhtml') && name.indexOf('-extracted') === -1) {
const fileName = name.split('/')[1].split('.')[0];
if (!isNaN(parseFloat(fileName))) {
valid = true;
Expand Down
14 changes: 8 additions & 6 deletions src/common/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,14 @@ export const parseWSchedule = (article: HTMLElement, content: HTMLElement, wLang

const studyDate = getWStudyDate(article);

if (isEnhancedParsing) {
const wStudyEnhanced = getWTStudyDateEnhanced(studyDate, wLang);
weekItem.w_study_date = wStudyEnhanced;
weekItem.w_study_date_locale = studyDate;
} else {
weekItem.w_study_date = studyDate;
if (studyDate.length > 0) {
if (isEnhancedParsing) {
const wStudyEnhanced = getWTStudyDateEnhanced(studyDate, wLang);
weekItem.w_study_date = wStudyEnhanced;
weekItem.w_study_date_locale = studyDate;
} else {
weekItem.w_study_date = studyDate;
}
}

const studyTitle = getWStudyTitle(article);
Expand Down
21 changes: 13 additions & 8 deletions src/common/parsing_rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,22 @@ export const extractMonthName = (src: string, lang: string) => {
let varDay;
let monthIndex;

const text = src.toLowerCase();
const split = text.split(/[–-—]/);
const monthNames = getMonthNames(lang);

for (const month of monthNames) {
const monthLang = month.name;
const regex = new RegExp(`(${monthLang.toLowerCase()})`);
const array = regex.exec(src.toLowerCase());
outerLoop: for (const splitted of split) {
for (const month of monthNames) {
const monthLang = month.name.toLowerCase();
const regex = new RegExp(`(${monthLang})`);

if (Array.isArray(array)) {
varDay = +src.match(/(\d+)/)![0];
monthIndex = month.index;
break;
const array = regex.exec(splitted);

if (Array.isArray(array)) {
varDay = +text.match(/(\d+)/)![0];
monthIndex = month.index;
break outerLoop;
}
}
}

Expand Down

0 comments on commit 2ad9482

Please sign in to comment.