From 2974c5413c388ed904cb95bc1ba6bc7aea0b5e21 Mon Sep 17 00:00:00 2001 From: nytpu Date: Fri, 19 Mar 2021 08:29:44 -0600 Subject: [PATCH] remove list command and instead write "subscriptions.gmi" & "feed.gmi" --- comitium.go | 10 ++++++---- core/core.go | 20 ------------------- core/entries.go | 50 ++++++++++++++++++++++++++++++++++++++++++---- doc/comitium.1.scd | 9 +++++---- doc/quickstart.md | 3 +++ flags.go | 2 -- 6 files changed, 60 insertions(+), 34 deletions(-) create mode 100644 doc/quickstart.md diff --git a/comitium.go b/comitium.go index 9714a23..418e220 100644 --- a/comitium.go +++ b/comitium.go @@ -59,12 +59,14 @@ func main() { fetch.RefreshAll(&core.Data, *refreshWorkersFlag) err = core.Data.WriteSubs(dataPath) 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) } - case "list": - argCheck(c.Args(), 0, false, "'list' doesn't take an argument!") - core.Data.Export(os.Stdout) case "add": argCheck(c.Args(), 1, true, "Please provide a URL to add.") diff --git a/core/core.go b/core/core.go index 0500771..afa20d0 100644 --- a/core/core.go +++ b/core/core.go @@ -81,23 +81,3 @@ func (d *FullData) WriteJSON(dataPath string) error { err = os.Rename(path, filepath.Join(dataPath, "comitium.json")) 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() -} diff --git a/core/entries.go b/core/entries.go index fb9ab25..3db8294 100644 --- a/core/entries.go +++ b/core/entries.go @@ -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 } diff --git a/doc/comitium.1.scd b/doc/comitium.1.scd index 4481e2c..20ed8d4 100644 --- a/doc/comitium.1.scd +++ b/doc/comitium.1.scd @@ -23,9 +23,6 @@ variety of feed formats: *refresh* [_FLAGS_] 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 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 @@ -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 manually edit. -*subscriptions.gmi* +*feed.gmi* The outputted text/gemini file containing the subscription items. Is what 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 This will add a new feed subscripton: diff --git a/doc/quickstart.md b/doc/quickstart.md new file mode 100644 index 0000000..0700104 --- /dev/null +++ b/doc/quickstart.md @@ -0,0 +1,3 @@ +# comitium quickstart + + diff --git a/flags.go b/flags.go index 372bf39..88d755a 100644 --- a/flags.go +++ b/flags.go @@ -22,7 +22,6 @@ type command struct { // info about all the accepted commands var commandInfo = []command{ {"refresh", "Check for new updates to subscriptions"}, - {"list", "List all subscriptions"}, {"add", "Add a new subscription"}, {"remove", "Remove a subscription"}, {"help", "Print usage information"}, @@ -31,7 +30,6 @@ var commandInfo = []command{ var commands = map[string]*flag.FlagSet{ "refresh": flag.NewFlagSet("refresh", flag.ExitOnError), - "list": flag.NewFlagSet("list", flag.ExitOnError), "add": flag.NewFlagSet("add", flag.ExitOnError), "remove": flag.NewFlagSet("remove", flag.ExitOnError), }