remove list command and instead write "subscriptions.gmi" & "feed.gmi"

This commit is contained in:
nytpu
2021-03-19 08:29:44 -06:00
parent db626e0c66
commit 2974c5413c
6 changed files with 60 additions and 34 deletions
+46 -4
View File
@@ -74,12 +74,54 @@ func toLocalDay(t time.Time) time.Time {
func (d *FullData) WriteSubs(dataPath string) error {
path := filepath.Join(dataPath, "subscriptions.gmi.new")
rawPage := `# comitium subscribed feeds
## Feeds
Gemini, Atom, RSS, and JSON feeds from all over.
`
d.FeedsMu.RLock()
for _, v := range d.Feeds {
rawPage += fmt.Sprintf("=> %v %v\n", v.FeedLink, v.Title)
}
d.FeedsMu.RUnlock()
rawPage += `
## Pages
Watching these pages for any changes that occur.
`
d.PagesMu.RLock()
for _, v := range d.Pages {
rawPage += fmt.Sprintf("=> %v", v.Link)
if v.Title != "" {
rawPage += fmt.Sprintf(" %v", v.Title)
}
rawPage += "\n"
}
d.PagesMu.RUnlock()
err := os.WriteFile(path, []byte(rawPage), 0666)
if err != nil {
return err
}
// if full write was successful then overwrite original
err = os.Rename(path, filepath.Join(dataPath, "subscriptions.gmi"))
return err
}
func (d *FullData) WriteFeed(dataPath string) error {
path := filepath.Join(dataPath, "feed.gmi.new")
rawPage := "# comitium subscriptions\n\n"
d.RLock()
pe := d.getPageEntries()
rawPage += fmt.Sprintf("=> subscriptions.gmi Currently aggregating %d capsules, gopherholes, and websites.\n", len(d.Feeds)+len(d.Pages))
d.RUnlock()
rawPage := "# Subscriptions"
if len(pe.Entries) > 0 {
curDay := toLocalDay(pe.Entries[0].Published)
rawPage += fmt.Sprintf("\n\n## %s\n\n", curDay.Format("2006-01-02"))
@@ -88,7 +130,7 @@ func (d *FullData) WriteSubs(dataPath string) error {
pub := toLocalDay(entry.Published)
if pub.Before(curDay) {
curDay = pub
rawPage += fmt.Sprintf("\n## %s\n\n", curDay.Format("2006-01-02"))
rawPage += fmt.Sprintf("\n\n## %s\n\n", curDay.Format("2006-01-02"))
}
if entry.Title == "" {
@@ -104,6 +146,6 @@ func (d *FullData) WriteSubs(dataPath string) error {
return err
}
// if full write was successful then overwrite original
err = os.Rename(path, filepath.Join(dataPath, "subscriptions.gmi"))
err = os.Rename(path, filepath.Join(dataPath, "feed.gmi"))
return err
}