1
mirror of https://github.com/jlelse/GoBlog synced 2024-05-30 12:14:28 +00:00
GoBlog/export.go
2024-04-22 15:49:22 +02:00

29 lines
537 B
Go

package main
import (
"cmp"
"os"
"path/filepath"
)
func (a *goBlog) exportMarkdownFiles(dir string) error {
posts, err := a.getPosts(&postsRequestConfig{
withoutRenderedTitle: true,
})
if err != nil {
return err
}
dir = cmp.Or(dir, "export")
for _, p := range posts {
filename := filepath.Join(dir, p.Path+".md")
filedir := filepath.Dir(filename)
_ = os.MkdirAll(filedir, 0777)
//nolint:gosec
err = os.WriteFile(filename, []byte(p.contentWithParams()), 0666)
if err != nil {
return err
}
}
return nil
}