began implementing dir traversal
This commit is contained in:
parent
3c8dd525f4
commit
3e6e481c0b
2 changed files with 33 additions and 5 deletions
|
@ -6,7 +6,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/ficcdaf/zona/internal/convert"
|
|
||||||
"github.com/ficcdaf/zona/internal/util"
|
"github.com/ficcdaf/zona/internal/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -42,9 +41,13 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if !validateFile(*mdPath, ".md") {
|
// if !validateFile(*mdPath, ".md") {
|
||||||
fmt.Println("File validation failed!")
|
// fmt.Println("File validation failed!")
|
||||||
os.Exit(1)
|
// os.Exit(1)
|
||||||
|
// }
|
||||||
|
// convert.ConvertFile(*mdPath, "test/test.html")
|
||||||
|
err := util.Traverse("test")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error: %s\n", err.Error())
|
||||||
}
|
}
|
||||||
convert.ConvertFile(*mdPath, "test/test.html")
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@ package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
@ -29,3 +31,26 @@ func PathIsValid(path string, requireFile bool) bool {
|
||||||
}
|
}
|
||||||
return err == nil
|
return err == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func processFile(path string, entry fs.DirEntry, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !entry.IsDir() {
|
||||||
|
ext := filepath.Ext(path)
|
||||||
|
switch ext {
|
||||||
|
case ".md":
|
||||||
|
fmt.Println("Processing markdown...")
|
||||||
|
default:
|
||||||
|
// All other file types, we copy!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Printf("Visited: %s\n", path)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func Traverse(root string) error {
|
||||||
|
// err := filepath.WalkDir(root, func(path string, entry fs.DirEntry, err error) error {
|
||||||
|
err := filepath.WalkDir(root, processFile)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue