mirror of
https://github.com/usememos/memos.git
synced 2025-02-21 21:57:47 +01:00
feat: remove RSS titles (#4140)
This removes the content of the <title> 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
This commit is contained in:
parent
51c80c37d1
commit
fcc4abf5b8
@ -5,13 +5,11 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/feeds"
|
"github.com/gorilla/feeds"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"github.com/usememos/gomark"
|
"github.com/usememos/gomark"
|
||||||
"github.com/usememos/gomark/ast"
|
|
||||||
"github.com/usememos/gomark/renderer"
|
"github.com/usememos/gomark/renderer"
|
||||||
|
|
||||||
storepb "github.com/usememos/memos/proto/gen/store"
|
storepb "github.com/usememos/memos/proto/gen/store"
|
||||||
@ -20,8 +18,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
maxRSSItemCount = 100
|
maxRSSItemCount = 100
|
||||||
maxRSSItemTitleLength = 128
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type RSSService struct {
|
type RSSService struct {
|
||||||
@ -112,7 +109,6 @@ func (s *RSSService) generateRSSFromMemoList(ctx context.Context, memoList []*st
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
feed.Items[i] = &feeds.Item{
|
feed.Items[i] = &feeds.Item{
|
||||||
Title: getRSSItemTitle(memo.Content),
|
|
||||||
Link: &feeds.Link{Href: baseURL + "/m/" + memo.UID},
|
Link: &feeds.Link{Href: baseURL + "/m/" + memo.UID},
|
||||||
Description: description,
|
Description: description,
|
||||||
Created: time.Unix(memo.CreatedTs, 0),
|
Created: time.Unix(memo.CreatedTs, 0),
|
||||||
@ -144,22 +140,6 @@ func (s *RSSService) generateRSSFromMemoList(ctx context.Context, memoList []*st
|
|||||||
return rss, nil
|
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) {
|
func getRSSItemDescription(content string) (string, error) {
|
||||||
nodes, err := gomark.Parse(content)
|
nodes, err := gomark.Parse(content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user