1
0
mirror of https://github.com/makew0rld/amfora.git synced 2024-06-25 19:55:22 +00:00
amfora/display/feeds.go

70 lines
1.8 KiB
Go
Raw Normal View History

2020-08-17 19:33:53 +00:00
package display
import (
"fmt"
"strings"
2020-08-17 21:36:50 +00:00
"time"
2020-08-17 19:33:53 +00:00
"github.com/makeworld-the-better-one/amfora/cache"
2020-08-17 19:33:53 +00:00
"github.com/makeworld-the-better-one/amfora/feeds"
"github.com/makeworld-the-better-one/amfora/renderer"
"github.com/makeworld-the-better-one/amfora/structs"
)
var feedPageRaw = "# Feeds & Pages\n\nUpdates" + strings.Repeat(" ", 80-25) + "[Newest -> Oldest]\n" +
strings.Repeat("-", 80) + "\n\n"
2020-08-17 21:36:50 +00:00
var timeDay = 24 * time.Hour
var feedPageUpdated time.Time
2020-08-17 19:33:53 +00:00
// Feeds displays the feeds page on the current tab.
func Feeds(t *tab) {
// Retrieve cached version if there hasn't been updates
p, ok := cache.GetPage("about:feeds")
if feedPageUpdated == feeds.LastUpdated && ok {
setPage(t, p)
t.applyBottomBar()
return
}
2020-08-17 19:33:53 +00:00
pe := feeds.GetPageEntries()
// curDay represents what day of posts the loop is on.
// It only goes backwards in time.
// It's initial setting means:
// only display posts older than a day in the future.
curDay := time.Now().Round(timeDay).Add(timeDay)
for _, entry := range pe.Entries { // From new to old
// Convert to local time, remove sub-day info
pub := entry.Published.In(time.Local).Round(timeDay)
2020-08-17 19:33:53 +00:00
if pub.Before(curDay) {
2020-08-17 19:33:53 +00:00
// This post is on a new day, add a day header
curDay := pub
2020-08-17 19:33:53 +00:00
feedPageRaw += fmt.Sprintf("\n## %s\n\n", curDay.Format("Jan 02, 2006"))
}
feedPageRaw += fmt.Sprintf("=>%s %s - %s\n", entry.URL, entry.Author, entry.Title)
}
content, links := renderer.RenderGemini(feedPageRaw, textWidth(), leftMargin())
page := structs.Page{
Raw: feedPageRaw,
Content: content,
Links: links,
2020-08-28 16:07:08 +00:00
URL: "about:feeds",
2020-08-17 19:33:53 +00:00
Width: termW,
Mediatype: structs.TextGemini,
}
cache.AddPage(&page)
2020-08-17 19:33:53 +00:00
setPage(t, &page)
t.applyBottomBar()
feedPageUpdated = time.Now()
}
func feedInit() {
// TODO
2020-08-17 19:33:53 +00:00
}