mirror of https://github.com/jlelse/GoBlog
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
538 B
Go
28 lines
538 B
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
func (a *goBlog) exportMarkdownFiles(dir string) error {
|
|
posts, err := a.getPosts(&postsRequestConfig{
|
|
withoutRenderedTitle: true,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
dir = defaultIfEmpty(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
|
|
}
|