add Export function to core.FullData
This commit is contained in:
@@ -15,6 +15,7 @@ package core
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -81,3 +82,23 @@ 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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user