|
|
|
@ -34,6 +34,7 @@ func scanReader(r io.Reader, path string, matchChan matches) {
|
|
|
|
|
for _, match := range matches {
|
|
|
|
|
dirs := strings.Split(path, "/")
|
|
|
|
|
noteFilename := dirs[len(dirs)-2]
|
|
|
|
|
log.Println("noteFilename:", noteFilename)
|
|
|
|
|
matchChan <- Attachment{Filename: match[1], Note: noteFilename}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -62,7 +63,7 @@ func walkFunc(matchChan matches) filepath.WalkFunc {
|
|
|
|
|
|
|
|
|
|
func moveAttachment(att Attachment, dest string) error {
|
|
|
|
|
destPath := filepath.Join(dest, strings.Split(att.Note, ".")[0])
|
|
|
|
|
log.Println("moving files:", destPath)
|
|
|
|
|
log.Println("moving files into:", destPath)
|
|
|
|
|
_, err := copy(att.Filename, filepath.Join(destPath, filepath.Base(att.Filename)))
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
@ -94,11 +95,9 @@ func copy(src, dst string) (int64, error) {
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
var (
|
|
|
|
|
origin string
|
|
|
|
|
destination string
|
|
|
|
|
target string
|
|
|
|
|
)
|
|
|
|
|
flag.StringVar(&origin, "origin", "./content/", "directory containing Obsidian Markdown posts")
|
|
|
|
|
flag.StringVar(&destination, "destination", "/tmp/blog/content/posts/", "destination for posts and their attachments")
|
|
|
|
|
flag.StringVar(&target, "target", "/tmp/blog/content/posts/", "target for posts and their attachments")
|
|
|
|
|
|
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
|
@ -107,7 +106,7 @@ func main() {
|
|
|
|
|
// for i := 0; i < 5; i++ {
|
|
|
|
|
go func() {
|
|
|
|
|
for match := range attachments {
|
|
|
|
|
err := moveAttachment(match, destination)
|
|
|
|
|
err := moveAttachment(match, target)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("error moving attachment: %s\n", err)
|
|
|
|
|
}
|
|
|
|
@ -115,7 +114,7 @@ func main() {
|
|
|
|
|
}()
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
err := filepath.Walk(origin, walkFunc(attachments))
|
|
|
|
|
err := filepath.Walk(target, walkFunc(attachments))
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("error walking %s", err)
|
|
|
|
|
}
|
|
|
|
|