- commit
- 37aba8d
- parent
- 0d7a174
- author
- Colin Henry
- date
- 2023-01-23 15:08:21 +0000 UTC
feat(feeds): add option to disable inlining of post content in feed.sh emails (#8)
3 files changed,
+21,
-4
+9,
-4
1@@ -43,7 +43,12 @@ type Feed struct {
2 }
3
4 type DigestFeed struct {
5- Feeds []*Feed
6+ Feeds []*Feed
7+ Options DigestOptions
8+}
9+
10+type DigestOptions struct {
11+ InlineContent bool
12 }
13
14 type Fetcher struct {
15@@ -120,7 +125,7 @@ func (f *Fetcher) RunPost(user *db.User, post *db.Post) error {
16 urls = append(urls, url)
17 }
18
19- msgBody, err := f.FetchAll(urls, post.Data.LastDigest)
20+ msgBody, err := f.FetchAll(urls, parsed.InlineContent, post.Data.LastDigest)
21 if err != nil {
22 return err
23 }
24@@ -272,9 +277,9 @@ type MsgBody struct {
25 Text string
26 }
27
28-func (f *Fetcher) FetchAll(urls []string, lastDigest *time.Time) (*MsgBody, error) {
29+func (f *Fetcher) FetchAll(urls []string, inlineContent bool, lastDigest *time.Time) (*MsgBody, error) {
30 fp := gofeed.NewParser()
31- feeds := &DigestFeed{}
32+ feeds := &DigestFeed{Options: DigestOptions{InlineContent: inlineContent}}
33
34 for _, url := range urls {
35 feedTmpl, err := f.Fetch(fp, url, lastDigest)
+3,
-0
1@@ -31,7 +31,10 @@ img {
2 <div>
3 <h1><a href="{{.Link}}">{{.Title}}</a></h1>
4 <div>{{.Description}}</div>
5+ {{if $.Options.InlineContent}}
6+ <div>{{.Description}}</div>
7 <div>{{.Content}}</div>
8+ {{end}}
9 </div>
10 <hr />
11 {{end}}
1@@ -5,6 +5,7 @@ import (
2 "html/template"
3 "log"
4 "regexp"
5+ "strconv"
6 "strings"
7 "time"
8
9@@ -51,6 +52,7 @@ type ListMetaData struct {
10 ListType string // https://developer.mozilla.org/en-US/docs/Web/CSS/list-style-type
11 DigestInterval string
12 Email string
13+ InlineContent bool // allows content inlining to be disabled in feeds.sh emails
14 }
15
16 var urlToken = "=>"
17@@ -128,6 +130,13 @@ func TokenToMetaField(meta *ListMetaData, token *SplitToken) error {
18 meta.DigestInterval = token.Value
19 } else if token.Key == "email" {
20 meta.Email = token.Value
21+ } else if token.Key == "inline_content" {
22+ v, err := strconv.ParseBool(token.Value)
23+ if err != nil {
24+ // its empty or its improperly configured, just send the content
25+ v = true
26+ }
27+ meta.InlineContent = v
28 }
29
30 return nil