diff --git a/pkg/feeds/feeds.go b/pkg/feeds/feeds.go index f868c56..06d0b9c 100644 --- a/pkg/feeds/feeds.go +++ b/pkg/feeds/feeds.go @@ -131,9 +131,19 @@ func makeEnclosure(feed *model.Feed, id string, lengthInBytes int64) (string, it return url, contentType, lengthInBytes } +func short(str string, i int) string { + runes := []rune(str) + if len(runes) > i { + return string(runes[:i]) + " ..." + } + + return str +} + func (s *Service) BuildFeed(hashID string) ([]byte, error) { const ( - cacheTTL = 30 * time.Minute + cacheTTL = 30 * time.Minute + maxDescriptionLen = 384 ) cached, err := s.cache.Get(hashID) @@ -164,6 +174,12 @@ func (s *Service) BuildFeed(hashID string) ([]byte, error) { return nil, err } + if len(feed.Episodes) > 300 { + for _, episode := range feed.Episodes { + episode.Description = short(episode.Description, maxDescriptionLen) + } + } + if oldLastID != feed.LastID { if err := s.storage.UpdateFeed(feed); err != nil { log.WithError(err).WithField("feed_id", hashID).Error("failed to save feed")