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
+6 -4
View File
@@ -59,12 +59,14 @@ func main() {
fetch.RefreshAll(&core.Data, *refreshWorkersFlag) fetch.RefreshAll(&core.Data, *refreshWorkersFlag)
err = core.Data.WriteSubs(dataPath) err = core.Data.WriteSubs(dataPath)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Error saving subscriptions: %v\n", err) fmt.Fprintf(os.Stderr, "Error writing subscriptions: %v\n", err)
os.Exit(1)
}
err = core.Data.WriteFeed(dataPath)
if err != nil {
fmt.Fprintf(os.Stderr, "Error writing feed: %v\n", err)
os.Exit(1) os.Exit(1)
} }
case "list":
argCheck(c.Args(), 0, false, "'list' doesn't take an argument!")
core.Data.Export(os.Stdout)
case "add": case "add":
argCheck(c.Args(), 1, true, "Please provide a URL to add.") argCheck(c.Args(), 1, true, "Please provide a URL to add.")
-20
View File
@@ -81,23 +81,3 @@ func (d *FullData) WriteJSON(dataPath string) error {
err = os.Rename(path, filepath.Join(dataPath, "comitium.json")) err = os.Rename(path, filepath.Join(dataPath, "comitium.json"))
return err return err
} }
func (d *FullData) Export(w io.Writer) {
fmt.Fprint(w, "# comitium subscribed feeds\n## Feeds\n\n")
d.FeedsMu.RLock()
for _, v := range d.Feeds {
fmt.Fprintf(w, "=> %v %v\n", v.FeedLink, v.Title)
}
d.FeedsMu.RUnlock()
fmt.Fprint(w, "\n\n## Pages\n\n")
d.PagesMu.RLock()
for _, v := range d.Pages {
fmt.Fprintf(w, "=> %v", v.Link)
if v.Title != "" {
fmt.Fprintf(w, " %v", v.Title)
}
fmt.Fprint(w, "\n")
}
d.PagesMu.RUnlock()
}
+46 -4
View File
@@ -74,12 +74,54 @@ func toLocalDay(t time.Time) time.Time {
func (d *FullData) WriteSubs(dataPath string) error { func (d *FullData) WriteSubs(dataPath string) error {
path := filepath.Join(dataPath, "subscriptions.gmi.new") 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() d.RLock()
pe := d.getPageEntries() pe := d.getPageEntries()
rawPage += fmt.Sprintf("=> subscriptions.gmi Currently aggregating %d capsules, gopherholes, and websites.\n", len(d.Feeds)+len(d.Pages))
d.RUnlock() d.RUnlock()
rawPage := "# Subscriptions"
if len(pe.Entries) > 0 { if len(pe.Entries) > 0 {
curDay := toLocalDay(pe.Entries[0].Published) curDay := toLocalDay(pe.Entries[0].Published)
rawPage += fmt.Sprintf("\n\n## %s\n\n", curDay.Format("2006-01-02")) 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) pub := toLocalDay(entry.Published)
if pub.Before(curDay) { if pub.Before(curDay) {
curDay = pub 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 == "" { if entry.Title == "" {
@@ -104,6 +146,6 @@ func (d *FullData) WriteSubs(dataPath string) error {
return err return err
} }
// if full write was successful then overwrite original // 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 return err
} }
+5 -4
View File
@@ -23,9 +23,6 @@ variety of feed formats:
*refresh* [_FLAGS_] *refresh* [_FLAGS_]
Check for new updates to subscriptions and update aggregator page. Check for new updates to subscriptions and update aggregator page.
*list*
List all subscriptions in a gemtext format suitable for remote bookmarking.
*add* [_FLAGS_] <_LINK_> [_TITLE_] *add* [_FLAGS_] <_LINK_> [_TITLE_]
Add a new subscription. _LINK_ is a link to the feed or watched URL. Add a new subscription. _LINK_ is a link to the feed or watched URL.
_TITLE_ is an optional title for the feed, otherwise a title will be _TITLE_ is an optional title for the feed, otherwise a title will be
@@ -98,10 +95,14 @@ Within the data directory, the following files are used:
subscription (change its title, update a link, etc) it should be trivial to subscription (change its title, update a link, etc) it should be trivial to
manually edit. manually edit.
*subscriptions.gmi* *feed.gmi*
The outputted text/gemini file containing the subscription items. Is what The outputted text/gemini file containing the subscription items. Is what
should be linked or copied to your server directory to publish it. should be linked or copied to your server directory to publish it.
*subscriptions.gmi*
A text/gemini list of all the feeds being aggregated, suitable for remote
bookmarking, etc. Should also be linked or copied to your server directory.
# EXAMPLES # EXAMPLES
This will add a new feed subscripton: This will add a new feed subscripton:
+3
View File
@@ -0,0 +1,3 @@
# comitium quickstart
-2
View File
@@ -22,7 +22,6 @@ type command struct {
// info about all the accepted commands // info about all the accepted commands
var commandInfo = []command{ var commandInfo = []command{
{"refresh", "Check for new updates to subscriptions"}, {"refresh", "Check for new updates to subscriptions"},
{"list", "List all subscriptions"},
{"add", "Add a new subscription"}, {"add", "Add a new subscription"},
{"remove", "Remove a subscription"}, {"remove", "Remove a subscription"},
{"help", "Print usage information"}, {"help", "Print usage information"},
@@ -31,7 +30,6 @@ var commandInfo = []command{
var commands = map[string]*flag.FlagSet{ var commands = map[string]*flag.FlagSet{
"refresh": flag.NewFlagSet("refresh", flag.ExitOnError), "refresh": flag.NewFlagSet("refresh", flag.ExitOnError),
"list": flag.NewFlagSet("list", flag.ExitOnError),
"add": flag.NewFlagSet("add", flag.ExitOnError), "add": flag.NewFlagSet("add", flag.ExitOnError),
"remove": flag.NewFlagSet("remove", flag.ExitOnError), "remove": flag.NewFlagSet("remove", flag.ExitOnError),
} }