# HG changeset patch # User neko259 # Date 2017-11-23 16:06:20 # Node ID 1a6f446b50257c76b95dad29ae4db468cad1d4ba # Parent 7b88902938c9e29b289a0ee178b3c47ffbc42afa Ellipsize fetched title if does not into the post 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 +