(hostName string, u *User, posts *[]PublicPost)
| 21 | ) |
| 22 | |
| 23 | func exportPostsCSV(hostName string, u *User, posts *[]PublicPost) []byte { |
| 24 | var b bytes.Buffer |
| 25 | |
| 26 | r := [][]string{ |
| 27 | {"id", "slug", "blog", "url", "created", "title", "body"}, |
| 28 | } |
| 29 | for _, p := range *posts { |
| 30 | var blog string |
| 31 | if p.Collection != nil { |
| 32 | blog = p.Collection.Alias |
| 33 | p.Collection.hostName = hostName |
| 34 | } |
| 35 | f := []string{p.ID, p.Slug.String, blog, p.CanonicalURL(hostName), p.Created8601(), p.Title.String, strings.Replace(p.Content, "\n", "\\n", -1)} |
| 36 | r = append(r, f) |
| 37 | } |
| 38 | |
| 39 | w := csv.NewWriter(&b) |
| 40 | w.WriteAll(r) // calls Flush internally |
| 41 | if err := w.Error(); err != nil { |
| 42 | log.Info("error writing csv: %v", err) |
| 43 | } |
| 44 | |
| 45 | return b.Bytes() |
| 46 | } |
| 47 | |
| 48 | type exportedTxt struct { |
| 49 | Name, Title, Body string |
no test coverage detected