diff --git a/cmd/obp/cmd/hugo.go b/cmd/obp/cmd/hugo.go index 1c375fe..e690fc6 100644 --- a/cmd/obp/cmd/hugo.go +++ b/cmd/obp/cmd/hugo.go @@ -13,8 +13,6 @@ import ( "code.ndumas.com/ndumas/obsidian-pipeline" ) -var source, target string - var hugoCmd = &cobra.Command{ Use: "hugo", Short: "convert a set of Obsidian notes into a Hugo compatible directory structure", @@ -26,6 +24,9 @@ var hugoCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { target := viper.GetString("target") source := viper.GetString("source") + log.Printf("provided source: %q\n", source) + log.Printf("provided target: %q\n", target) + return nil err := obp.CopyPosts(source, target) if err != nil { @@ -47,18 +48,19 @@ var hugoCmd = &cobra.Command{ func init() { hugoCmd.Flags().StringP("source", "s", "", "path to vault directory containing hugo posts") - hugoCmd.Flags().StringP("target", "t", "", "hugo content/ directory") - hugoCmd.MarkFlagsRequiredTogether("source", "target") err := viper.BindPFlag("source", hugoCmd.Flags().Lookup("source")) if err != nil { log.Panicln("error binding viper to source flag:", err) } + hugoCmd.Flags().StringP("target", "t", "", "hugo content/ directory") err = viper.BindPFlag("target", hugoCmd.Flags().Lookup("target")) if err != nil { log.Panicln("error binding viper to target flag:", err) } + hugoCmd.MarkFlagsRequiredTogether("source", "target") + rootCmd.AddCommand(hugoCmd) } diff --git a/hugo.go b/hugo.go index 10cb9ff..b5d3f2b 100644 --- a/hugo.go +++ b/hugo.go @@ -10,13 +10,6 @@ import ( ) func CopyPosts(src, dst string) error { - /* - err := os.MkdirAll(dst, 0777) - if err != nil && !os.IsExist(err) { - return fmt.Errorf("error creating target directory %q: %w", dst, err) - } - */ - posts := make([]string, 0) srcRoot := os.DirFS(src) @@ -39,7 +32,25 @@ func CopyPosts(src, dst string) error { if err != nil { return fmt.Errorf("walkfunc failed: %w", err) } - log.Printf("%#+v\n", posts) + + for _, post := range posts { + base := filepath.Base(post) + + splitPostName := strings.Split(base, ".") + + postName := strings.Join(splitPostName[:len(splitPostName)-1], ".") + + log.Printf("provided dst: %q\n", dst) + postDir := filepath.Join(dst, postName) + log.Printf("postDir: %q\n", postDir) + return nil + + err := os.MkdirAll(postDir, 0777) + + if err != nil && !os.IsExist(err) { + return fmt.Errorf("error creating target directory %q: %w", dst, err) + } + } return nil }