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

48 lines
1.2 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/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
2020-08-17 19:33:53 +00:00
// Feeds displays the feeds page on the current tab.
func Feeds(t *tab) {
// TODO; Decide about date in local time vs UTC
// TODO: Cache
pe := feeds.GetPageEntries()
2020-08-17 21:36:50 +00:00
curDay := time.Time{}.Round(timeDay)
2020-08-17 19:33:53 +00:00
for _, entry := range pe.Entries {
2020-08-17 21:36:50 +00:00
if entry.Published.Round(timeDay).After(curDay) {
2020-08-17 19:33:53 +00:00
// This post is on a new day, add a day header
2020-08-17 21:36:50 +00:00
curDay := entry.Published.Round(timeDay)
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,
}
setPage(t, &page)
t.applyBottomBar()
}