diff options
author | Adam Mathes <adam@trenchant.org> | 2018-07-04 14:58:43 -0700 |
---|---|---|
committer | Adam Mathes <adam@trenchant.org> | 2018-07-04 14:58:43 -0700 |
commit | ee5bf1d50b9165729d0c61f7d1f968949e3e0638 (patch) | |
tree | 2c95b0a2a7563d7882712676f99d78cd6f563d93 /exporter | |
parent | d0911491b52a56f713da9ebe26f993bf786cce84 (diff) | |
download | neko-ee5bf1d50b9165729d0c61f7d1f968949e3e0638.tar.gz neko-ee5bf1d50b9165729d0c61f7d1f968949e3e0638.tar.bz2 neko-ee5bf1d50b9165729d0c61f7d1f968949e3e0638.zip |
enable feed export from web interface
Diffstat (limited to 'exporter')
-rw-r--r-- | exporter/exporter.go | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/exporter/exporter.go b/exporter/exporter.go index 04ced0b..013377d 100644 --- a/exporter/exporter.go +++ b/exporter/exporter.go @@ -2,37 +2,38 @@ package exporter import ( "adammathes.com/neko/models/feed" + "bytes" "encoding/json" "encoding/xml" "fmt" "html/template" - "os" ) -func ExportFeeds(format string) { +func ExportFeeds(format string) string { feeds, err := feed.All() if err != nil { panic(err) } + s := "" switch format { case "text": for _, f := range feeds { - fmt.Printf("%s\n", f.Url) + s = s + fmt.Sprintf("%s\n", f.Url) } case "opml": - fmt.Printf(`<opml version="2.0"><head><title>neko feeds</title></head><body>`) - fmt.Printf("\n") + s = s + fmt.Sprintf(`<opml version="2.0"><head><title>neko feeds</title></head><body>`) + s = s + fmt.Sprintf("\n") for _, f := range feeds { b, _ := xml.Marshal(f) - fmt.Printf("%s\n", string(b)) + s = s + fmt.Sprintf("%s\n", string(b)) } - fmt.Printf(`</body></opml>`) + s = s + fmt.Sprintf(`</body></opml>`) case "json": js, _ := json.Marshal(feeds) - fmt.Printf("%s\n", js) + s = fmt.Sprintf("%s\n", js) case "html": htmlTemplateString := `<html> @@ -48,10 +49,14 @@ func ExportFeeds(format string) { </ul> </body> </html>` + var bts bytes.Buffer htmlTemplate, err := template.New("feeds").Parse(htmlTemplateString) - err = htmlTemplate.Execute(os.Stdout, feeds) + err = htmlTemplate.Execute(&bts, feeds) if err != nil { panic(err) } + s = bts.String() } + + return s } |