MCPcopy Index your code
hub / github.com/writefreely/writefreely / exportPostsCSV

Function exportPostsCSV

export.go:23–46  ·  view source on GitHub ↗
(hostName string, u *User, posts *[]PublicPost)

Source from the content-addressed store, hash-verified

21)
22
23func 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
48type exportedTxt struct {
49 Name, Title, Body string

Callers 1

viewExportPostsFunction · 0.85

Calls 2

CanonicalURLMethod · 0.45
Created8601Method · 0.45

Tested by

no test coverage detected