From ad1c6ae0b252cddce96af9b8f477cccd7f287f91 Mon Sep 17 00:00:00 2001 From: Nick Dumas Date: Sat, 4 Mar 2023 15:31:28 -0500 Subject: [PATCH] working, live version --- main.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index ea5c090..7e22b15 100644 --- a/main.go +++ b/main.go @@ -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) }