diff --git a/go.mod b/go.mod index 979a4ca..d37e636 100644 --- a/go.mod +++ b/go.mod @@ -6,3 +6,5 @@ require ( github.com/gomarkdown/markdown v0.0.0-20241105142532-d03b89096d81 gopkg.in/yaml.v3 v3.0.1 ) + +require golang.org/x/text v0.20.0 // indirect diff --git a/internal/build/build_page.go b/internal/build/build_page.go index bcb5a38..2337213 100644 --- a/internal/build/build_page.go +++ b/internal/build/build_page.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "html/template" - "path/filepath" "strings" "gopkg.in/yaml.v3" @@ -42,17 +41,10 @@ func processWithYaml(f []byte) (Metadata, []byte, error) { return meta, []byte(split[2]), nil } -// this function converts a file path to its title form -func pathToTitle(path string) string { - stripped := ChangeExtension(filepath.Base(path), "") - replaced := strings.NewReplacer("-", " ", "_", " ", `\ `, " ").Replace(stripped) - return strings.ToTitle(replaced) -} - func buildPageData(m Metadata, path string) *PageData { p := &PageData{} if title, ok := m["title"].(string); ok { - p.Title = title + p.Title = wordsToTitle(title) } else { p.Title = pathToTitle(path) } @@ -89,6 +81,7 @@ func ConvertFile(in string, out string) error { return err } pd := buildPageData(metadata, in) + fmt.Println("Title: ", pd.Title) // build according to template here html, err := MdToHTML(md) diff --git a/internal/build/convert.go b/internal/build/convert.go index 740e07c..cd1602b 100644 --- a/internal/build/convert.go +++ b/internal/build/convert.go @@ -42,11 +42,11 @@ func PathIsValid(path string, requireFile bool) bool { } func processLink(p string) string { - fmt.Println("Processing link...") + // fmt.Println("Processing link...") ext := filepath.Ext(p) // Only process if it points to an existing, local markdown file if ext == ".md" && filepath.IsLocal(p) { - fmt.Println("Markdown link detected...") + // fmt.Println("Markdown link detected...") return ChangeExtension(p, ".html") } else { return p diff --git a/internal/build/title.go b/internal/build/title.go new file mode 100644 index 0000000..704e0b2 --- /dev/null +++ b/internal/build/title.go @@ -0,0 +1,30 @@ +package build + +import ( + "path/filepath" + "strings" + + "golang.org/x/text/cases" + "golang.org/x/text/language" +) + +// pathToWords takes a full path +// and strips separators and extension +// from the file name +func pathToWords(path string) string { + stripped := ChangeExtension(filepath.Base(path), "") + replaced := strings.NewReplacer("-", " ", "_", " ", `\ `, " ").Replace(stripped) + return strings.ToTitle(replaced) +} + +func wordsToTitle(words string) string { + caser := cases.Title(language.English) + return caser.String(words) +} + +// pathToTitle converts a full path to a string +// in title case +func pathToTitle(path string) string { + words := pathToWords(path) + return wordsToTitle(words) +} diff --git a/internal/build/traverse.go b/internal/build/traverse.go index f0bc090..379fe8b 100644 --- a/internal/build/traverse.go +++ b/internal/build/traverse.go @@ -2,7 +2,6 @@ package build import ( "errors" - "fmt" "io/fs" "path/filepath" @@ -18,7 +17,7 @@ func processFile(inPath string, entry fs.DirEntry, err error, outRoot string) er outPath := util.ReplaceRoot(inPath, outRoot) switch ext { case ".md": - fmt.Println("Processing markdown...") + // fmt.Println("Processing markdown...") outPath = ChangeExtension(outPath, ".html") if err := util.CreateParents(outPath); err != nil { return err diff --git a/runtest.sh b/runtest.sh index d20c26e..27611e4 100755 --- a/runtest.sh +++ b/runtest.sh @@ -5,4 +5,4 @@ fi go run cmd/zona/main.go test -bat foobar/in.html +# bat foobar/in.html diff --git a/test/this-article-has-a-title.md b/test/this-article-has-a-title.md new file mode 100644 index 0000000..578595f --- /dev/null +++ b/test/this-article-has-a-title.md @@ -0,0 +1,6 @@ +# My amazing markdown file! + +I can _even_ do **this**! + +- Or, I could... +- [Link](page.md) to this file