refactoring; began implementing embedding
This commit is contained in:
parent
12ebba687b
commit
4d1b18fd12
11 changed files with 96 additions and 50 deletions
|
@ -18,6 +18,10 @@ func CheckExtension(path, ext string) error {
|
|||
}
|
||||
}
|
||||
|
||||
func ChangeExtension(in string, outExt string) string {
|
||||
return strings.TrimSuffix(in, filepath.Ext(in)) + outExt
|
||||
}
|
||||
|
||||
func getRoot(path string) string {
|
||||
for {
|
||||
parent := filepath.Dir(path)
|
||||
|
|
30
internal/util/title.go
Normal file
30
internal/util/title.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
package util
|
||||
|
||||
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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue