From fcc4abf5b8be6269410421dec5d0fd31a8d53338 Mon Sep 17 00:00:00 2001 From: JP Hastings-Edrei Date: Wed, 20 Nov 2024 14:31:32 +0000 Subject: [PATCH] feat: remove RSS titles (#4140) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This removes the content of the element in the RSS feeds that Memo produces. Why remove? Every RSS client I can find shows the <title> next to the <description> when viewing an item. This creates a duplicate (but often trimmed, so less useful) version of <description> right above the actual text the user wants to read (often in a much larger font). It similarly makes lists of items in some clients extremely tall, as 128 characters is a lot of hard-to-read text — especially when Memos renders links as their URL in titles. Why an empty tag? The RSS 1.0 and 2.0 specs require that a <title> element is present. Examples from elsewhere: - micro.blog uses an empty <title /> element: https://www.manton.org/feed.xml - Bluesky omits the <title> element: https://bsky.app/profile/did%3Aplc%3Aqvzn322kmcvd7xtnips5xaun/rss - Mastodon omits the <title> element: https://mastodon.social/@scalzi.rss --- server/router/rss/rss.go | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/server/router/rss/rss.go b/server/router/rss/rss.go index 1959e27a3ab6f..4098702e31a19 100644 --- a/server/router/rss/rss.go +++ b/server/router/rss/rss.go @@ -5,13 +5,11 @@ import ( "fmt" "net/http" "strconv" - "strings" "time" "github.com/gorilla/feeds" "github.com/labstack/echo/v4" "github.com/usememos/gomark" - "github.com/usememos/gomark/ast" "github.com/usememos/gomark/renderer" storepb "github.com/usememos/memos/proto/gen/store" @@ -20,8 +18,7 @@ import ( ) const ( - maxRSSItemCount = 100 - maxRSSItemTitleLength = 128 + maxRSSItemCount = 100 ) type RSSService struct { @@ -112,7 +109,6 @@ func (s *RSSService) generateRSSFromMemoList(ctx context.Context, memoList []*st return "", err } feed.Items[i] = &feeds.Item{ - Title: getRSSItemTitle(memo.Content), Link: &feeds.Link{Href: baseURL + "/m/" + memo.UID}, Description: description, Created: time.Unix(memo.CreatedTs, 0), @@ -144,22 +140,6 @@ func (s *RSSService) generateRSSFromMemoList(ctx context.Context, memoList []*st return rss, nil } -func getRSSItemTitle(content string) string { - nodes, _ := gomark.Parse(content) - if len(nodes) > 0 { - firstNode := nodes[0] - title := renderer.NewStringRenderer().Render([]ast.Node{firstNode}) - return title - } - - title := strings.Split(content, "\n")[0] - var titleLengthLimit = min(len(title), maxRSSItemTitleLength) - if titleLengthLimit < len(title) { - title = title[:titleLengthLimit] + "..." - } - return title -} - func getRSSItemDescription(content string) (string, error) { nodes, err := gomark.Parse(content) if err != nil {