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.
62 lines
1.1 KiB
Go
62 lines
1.1 KiB
Go
package obp
|
|
|
|
import (
|
|
"fmt"
|
|
"io/fs"
|
|
// "log"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
func CopyPosts(src, dst string) error {
|
|
posts := make([]string, 0)
|
|
|
|
srcRoot := os.DirFS(src)
|
|
err := fs.WalkDir(srcRoot, ".", func(path string, d fs.DirEntry, err error) error {
|
|
// here's where I walk through the source directory and collect all the markdown notes
|
|
if err != nil {
|
|
return fmt.Errorf("could not walk %q: %w", path, err)
|
|
}
|
|
|
|
if d.IsDir() {
|
|
return nil
|
|
}
|
|
|
|
if strings.HasSuffix(path, ".md") {
|
|
posts = append(posts, filepath.Join(src, path))
|
|
}
|
|
|
|
return nil
|
|
})
|
|
if err != nil {
|
|
return fmt.Errorf("walkfunc failed: %w", err)
|
|
}
|
|
|
|
for _, post := range posts {
|
|
base := filepath.Base(post)
|
|
|
|
splitPostName := strings.Split(base, ".")
|
|
|
|
postName := strings.Join(splitPostName[:len(splitPostName)-1], ".")
|
|
|
|
postDir := filepath.Join(dst, postName)
|
|
|
|
err := os.MkdirAll(postDir, 0777)
|
|
|
|
if err != nil && !os.IsExist(err) {
|
|
return fmt.Errorf("error creating target directory %q: %w", dst, err)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func Sanitize(src string) error {
|
|
return nil
|
|
}
|
|
|
|
func GatherMedia(src string) error {
|
|
return nil
|
|
}
|