From 8ec5533a06ff2b686c3b0f58767a9ac24446da9e Mon Sep 17 00:00:00 2001 From: Fabian Meyer <3982806+meyfa@users.noreply.github.com> Date: Mon, 1 Jul 2024 15:31:00 +0200 Subject: [PATCH] fix: Do not rely on .article-div (#262) SW-KA have pushed an update where some wrapper elements are no longer present on the page. This breaks 'simplesite' plan parsing. By simplifying the DOM selector, this patch restores it to a working condition while keeping backwards-compatibility. --- src/simplesite/simplesite-parse.ts | 2 +- test/simplesite/simplesite-parse.test.ts | 22 +++++++++------------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/simplesite/simplesite-parse.ts b/src/simplesite/simplesite-parse.ts index 0c9261a..61e3270 100644 --- a/src/simplesite/simplesite-parse.ts +++ b/src/simplesite/simplesite-parse.ts @@ -122,7 +122,7 @@ function parseMeal ($: CheerioAPI, $row: Cheerio): CanteenMeal | undefi */ export function parse (html: string, canteenId: string, referenceDate: Date): CanteenPlan[] { const $ = load(html) - const $titles = $('#platocontent .article-div > h1') + const $titles = $('#platocontent h1') // The canteen name is stored in the first

. const canteenName = $titles.first().text() diff --git a/test/simplesite/simplesite-parse.test.ts b/test/simplesite/simplesite-parse.test.ts index 80a6452..01dd01a 100644 --- a/test/simplesite/simplesite-parse.test.ts +++ b/test/simplesite/simplesite-parse.test.ts @@ -20,19 +20,15 @@ function wrapContent (canteenName: string, content: string): string {
-
-
-

${canteenName}

-

${canteenName}

- Preise für Studenten -

- ${content} - Legende
- (1) mit Farbstoff
- Freiwillige Angaben
- [R] enthält Rindfleisch -
-
+

${canteenName}

+

${canteenName}

+ Preise für Studierende +

+ ${content} + Legende
+ (1) mit Farbstoff
+ Freiwillige Angaben
+ [R] enthält Rindfleisch