|
| 1 | +import re |
1 | 2 | from collections.abc import Sequence |
2 | 3 | from dataclasses import dataclass, field |
3 | 4 | from datetime import datetime, time, timedelta |
@@ -85,6 +86,14 @@ def get_day_start_end(self, dt: datetime, start_time: time = time(4, 0)) -> tupl |
85 | 86 |
|
86 | 87 | return start_dt, end_dt |
87 | 88 |
|
| 89 | + def slugify(self, title: str) -> str: |
| 90 | + title = re.sub(WHITESPACE_REGEX, "-", title) |
| 91 | + title = title.lower() |
| 92 | + title = unicodedata.normalize("NFD", title).encode("ASCII", "ignore").decode() |
| 93 | + title = re.sub(FRAB_SLUG_REGEX, "", title) |
| 94 | + title = title.strip("-") |
| 95 | + return title |
| 96 | + |
88 | 97 | @cached_property |
89 | 98 | def schedule(self): |
90 | 99 | # This is basically a reimplementation of get_schedule_item_dicts_flat |
@@ -230,7 +239,7 @@ def run(self): |
230 | 239 | flat_sid["occurrences"][0]["end_date"], |
231 | 240 | ), |
232 | 241 | "room": room["name"], |
233 | | - "slug": f"""emf{event_year()}-{flat_sid["id"]}-{flat_sid["occurrences"][0]["occurrence_num"]}-{flat_sid["slug"]}""", |
| 242 | + "slug": f"""emf{event_year()}-{flat_sid["id"]}-{flat_sid["occurrences"][0]["occurrence_num"]}-{self.slugify(flat_sid["title"])}""", |
234 | 243 | "url": flat_sid["link"], |
235 | 244 | "title": flat_sid["title"], |
236 | 245 | "subtitle": "", |
@@ -359,7 +368,7 @@ def add_event(self, room: Element, room_name: str, flat_sid: ScheduleItemDict) - |
359 | 368 | self._add_sub_with_text(event, "abstract", flat_sid["description"]) |
360 | 369 | self._add_sub_with_text(event, "description", "") |
361 | 370 |
|
362 | | - slug = f"""emf{event_year()}-{flat_sid["id"]}-{flat_sid["occurrences"][0]["occurrence_num"]}-{flat_sid["slug"]}""" |
| 371 | + slug = f"""emf{event_year()}-{flat_sid["id"]}-{flat_sid["occurrences"][0]["occurrence_num"]}-{self.slugify(flat_sid["title"])}""" |
363 | 372 | self._add_sub_with_text(event, "slug", slug) |
364 | 373 |
|
365 | 374 | self._add_sub_with_text(event, "subtitle", "") |
|
0 commit comments