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
|
|
|
|
2020-08-28 23:33:37 +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
|
|
|
|
|
2020-08-28 23:33:37 +00:00
|
|
|
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) {
|
2020-08-28 23:33:37 +00:00
|
|
|
// 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()
|
|
|
|
|
2020-08-28 23:33:37 +00:00
|
|
|
// 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
|
|
|
|
2020-08-28 23:33:37 +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
|
2020-08-28 23:33:37 +00:00
|
|
|
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,
|
|
|
|
}
|
2020-08-28 23:33:37 +00:00
|
|
|
cache.AddPage(&page)
|
2020-08-17 19:33:53 +00:00
|
|
|
setPage(t, &page)
|
|
|
|
t.applyBottomBar()
|
2020-08-28 23:33:37 +00:00
|
|
|
|
|
|
|
feedPageUpdated = time.Now()
|
|
|
|
}
|
|
|
|
|
|
|
|
func feedInit() {
|
|
|
|
// TODO
|
2020-08-17 19:33:53 +00:00
|
|
|
}
|