1
0
mirror of https://github.com/mxpv/podsync.git synced 2024-05-11 05:55:04 +00:00

Truncate long episode descriptions

This commit is contained in:
Maksym Pavlenko
2019-04-06 13:28:36 -07:00
parent 20bf7c7e53
commit 929041c692

View File

@ -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")