diff --git a/boards/models/source.py b/boards/models/source.py --- a/boards/models/source.py +++ b/boards/models/source.py @@ -57,7 +57,7 @@ class ThreadSource(models.Model): feed = feedparser.parse(self.source) items = sorted(feed.entries, key=lambda entry: entry.published_parsed) for item in items: - title = item.title[:TITLE_MAX_LENGTH] + title = self.strip_title(item.title, TITLE_MAX_LENGTH) timestamp = datetime.fromtimestamp(calendar.timegm(item.published_parsed), tz=utc) if not timestamp: logger.error('Invalid timestamp {} for {}'.format(item.published, title)) @@ -75,3 +75,10 @@ class ThreadSource(models.Model): def parse_text(self, text): return strip_tags(text) + + def strip_title(self, title, max_length): + result = title + if len(title) > max_length: + result = title[:max_length - 1] + '…' + return result +