aboutsummaryrefslogtreecommitdiffstats
path: root/exporter
diff options
context:
space:
mode:
authorAdam Mathes <adam@trenchant.org>2018-04-08 08:51:26 -0700
committerAdam Mathes <adam@trenchant.org>2018-04-08 08:51:26 -0700
commitcd1509967d7dafbf2d1a051206e368bd3aa5e179 (patch)
treedbcf7629eaaa3e04409c1c949072ebaf06d9436e /exporter
parente0702a70437eea543aaa51264272dcbc3d652779 (diff)
downloadneko-cd1509967d7dafbf2d1a051206e368bd3aa5e179.tar.gz
neko-cd1509967d7dafbf2d1a051206e368bd3aa5e179.tar.bz2
neko-cd1509967d7dafbf2d1a051206e368bd3aa5e179.zip
refactor exporter, add json/opml export formats
Diffstat (limited to 'exporter')
-rw-r--r--exporter/exporter.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/exporter/exporter.go b/exporter/exporter.go
new file mode 100644
index 0000000..8e7ff12
--- /dev/null
+++ b/exporter/exporter.go
@@ -0,0 +1,47 @@
+package exporter
+
+import (
+ "adammathes.com/neko/config"
+ "adammathes.com/neko/models/feed"
+ "encoding/json"
+ "encoding/xml"
+ "fmt"
+ "html/template"
+ "os"
+ "path"
+)
+
+func ExportFeeds(format string) {
+ feeds, err := feed.All()
+ if err != nil {
+ panic(err)
+ }
+
+ switch format {
+ case "text":
+ for _, f := range feeds {
+ fmt.Printf("%s\n", f.Url)
+ }
+
+ case "opml":
+ fmt.Printf(`<opml version="2.0"><head><title>neko feeds</title></head><body>`)
+ fmt.Printf("\n")
+ for _, f := range feeds {
+ b, _ := xml.Marshal(f)
+ fmt.Printf("%s\n", string(b))
+ }
+ fmt.Printf(`</body></opml>`)
+
+ case "json":
+ js, _ := json.Marshal(feeds)
+ fmt.Printf("%s\n", js)
+
+ case "html":
+ tmplFile := path.Join(config.Config.StaticDir, "feeds.tmpl")
+ feedsTmpl := template.Must(template.ParseFiles(tmplFile))
+ err := feedsTmpl.Execute(os.Stdout, feeds)
+ if err != nil {
+ panic(err)
+ }
+ }
+}