Implemented proper conversion of links to local markdown files into html links

This commit is contained in:
Daniel Fichtinger 2024-11-24 17:47:08 -05:00
parent 46e4f483f6
commit 7915a4bb09
7 changed files with 92 additions and 28 deletions

View file

@ -22,19 +22,6 @@ func CheckExtension(path, ext string) error {
}
}
// PathIsValid checks if a path is valid.
// If requireFile is set, directories are not considered valid.
func PathIsValid(path string, requireFile bool) bool {
s, err := os.Stat(path)
if os.IsNotExist(err) {
return false
} else if requireFile {
// fmt.Printf("Directory status: %s\n", strconv.FormatBool(s.IsDir()))
return !s.IsDir()
}
return err == nil
}
func getRoot(path string) string {
for {
parent := filepath.Dir(path)
@ -43,7 +30,7 @@ func getRoot(path string) string {
}
path = parent
}
fmt.Println("getRoot: ", path)
// fmt.Println("getRoot: ", path)
return path
}
@ -73,7 +60,7 @@ func processFile(inPath string, entry fs.DirEntry, err error, outRoot string) er
if !entry.IsDir() {
ext := filepath.Ext(inPath)
outPath := replaceRoot(inPath, outRoot)
fmt.Println("NewRoot: ", outPath)
// fmt.Println("NewRoot: ", outPath)
switch ext {
case ".md":
fmt.Println("Processing markdown...")
@ -99,7 +86,7 @@ func processFile(inPath string, entry fs.DirEntry, err error, outRoot string) er
}
}
}
fmt.Printf("Visited: %s\n", inPath)
// fmt.Printf("Visited: %s\n", inPath)
return nil
}

15
internal/util/util.go Normal file
View file

@ -0,0 +1,15 @@
package util
import "strings"
func NormalizeContent(content string) string {
var normalized []string
lines := strings.Split(content, "\n")
for _, line := range lines {
line = strings.TrimSpace(line)
if line != "" {
normalized = append(normalized, line)
}
}
return strings.Join(normalized, "\n")
}