repos / pico

pico services - prose.sh, pastes.sh, imgs.sh, feeds.sh, pgs.sh
git clone https://github.com/picosh/pico.git

commit
ae3f389
parent
b671467
author
Eric Bower
date
2024-10-13 04:57:02 +0000 UTC
refactor(feeds): only show banner notice when <30 days

feat(feeds): extend engagement click once every 6 months
3 files changed,  +14, -3
M feeds/cron.go
+10, -3
 1@@ -63,6 +63,7 @@ type DigestFeed struct {
 2 	Options      DigestOptions
 3 	KeepAliveURL string
 4 	DaysLeft     string
 5+	ShowBanner   bool
 6 }
 7 
 8 type DigestOptions struct {
 9@@ -187,7 +188,7 @@ func (f *Fetcher) RunPost(logger *slog.Logger, user *db.User, post *db.Post) err
10 
11 	now := time.Now().UTC()
12 	if post.ExpiresAt == nil {
13-		expiresAt := time.Now().AddDate(0, 3, 0)
14+		expiresAt := time.Now().AddDate(0, 6, 0)
15 		post.ExpiresAt = &expiresAt
16 	}
17 	post.Data.LastDigest = &now
18@@ -331,14 +332,20 @@ type MsgBody struct {
19 
20 func (f *Fetcher) FetchAll(logger *slog.Logger, urls []string, inlineContent bool, username string, post *db.Post) (*MsgBody, error) {
21 	fp := gofeed.NewParser()
22-	daysLeft := "90"
23+	daysLeft := ""
24+	showBanner := false
25 	if post.ExpiresAt != nil {
26 		diff := time.Until(*post.ExpiresAt)
27-		daysLeft = fmt.Sprintf("%f", math.Ceil(diff.Hours()/24))
28+		daysLeftInt := int(math.Ceil(diff.Hours() / 24))
29+		daysLeft = fmt.Sprintf("%d", daysLeftInt)
30+		if daysLeftInt <= 30 {
31+			showBanner = true
32+		}
33 	}
34 	feeds := &DigestFeed{
35 		KeepAliveURL: fmt.Sprintf("https://feeds.pico.sh/keep-alive/%s", post.ID),
36 		DaysLeft:     daysLeft,
37+		ShowBanner:   showBanner,
38 		Options:      DigestOptions{InlineContent: inlineContent},
39 	}
40 	feedItems, err := f.db.FindFeedItemsByPostID(post.ID)
M feeds/html/digest.page.tmpl
+2, -0
 1@@ -9,10 +9,12 @@ img {
 2 }
 3 </style>
 4 
 5+{{if .ShowBanner}}
 6 <blockquote>
 7   In order to keep this digest email active you must <a href="{{.KeepAliveURL}}">click this link</a>.
 8   You have {{.DaysLeft}} days left.
 9 </blockquote>
10+{{end}}
11 
12 <div class="feeds">
13 {{range .Feeds}}
M feeds/html/digest_text.page.tmpl
+2, -0
1@@ -1,5 +1,7 @@
2+{{if .ShowBanner}}
3 > In order to keep this digest email active you must click the link below. You have {{.DaysLeft}} days left.
4 > {{.KeepAliveURL}}
5+{{end}}
6 
7 {{range .Feeds}}
8     {{.Title}}