diff options
Diffstat (limited to 'helpers')
-rw-r--r-- | helpers/general.go | 30 | ||||
-rw-r--r-- | helpers/path.go | 9 |
2 files changed, 8 insertions, 31 deletions
diff --git a/helpers/general.go b/helpers/general.go index aa1e00d3a..80e303087 100644 --- a/helpers/general.go +++ b/helpers/general.go @@ -437,36 +437,6 @@ func NormalizeHugoFlags(f *pflag.FlagSet, name string) pflag.NormalizedName { return pflag.NormalizedName(name) } -// DiffStringSlices returns the difference between two string slices. -// Useful in tests. -// See: -// http://stackoverflow.com/questions/19374219/how-to-find-the-difference-between-two-slices-of-strings-in-golang -func DiffStringSlices(slice1 []string, slice2 []string) []string { - diffStr := []string{} - m := map[string]int{} - - for _, s1Val := range slice1 { - m[s1Val] = 1 - } - for _, s2Val := range slice2 { - m[s2Val] = m[s2Val] + 1 - } - - for mKey, mVal := range m { - if mVal == 1 { - diffStr = append(diffStr, mKey) - } - } - - return diffStr -} - -// DiffStrings splits the strings into fields and runs it into DiffStringSlices. -// Useful for tests. -func DiffStrings(s1, s2 string) []string { - return DiffStringSlices(strings.Fields(s1), strings.Fields(s2)) -} - // PrintFs prints the given filesystem to the given writer starting from the given path. // This is useful for debugging. func PrintFs(fs afero.Fs, path string, w io.Writer) { diff --git a/helpers/path.go b/helpers/path.go index d97789e15..29e1e6071 100644 --- a/helpers/path.go +++ b/helpers/path.go @@ -18,6 +18,7 @@ import ( "fmt" "io" "os" + "path" "path/filepath" "regexp" "sort" @@ -243,13 +244,19 @@ func FileAndExtNoDelimiter(in string) (string, string) { return file, strings.TrimPrefix(ext, ".") } -// Filename takes a path, strips out the extension, +// Filename takes a file path, strips out the extension, // and returns the name of the file. func Filename(in string) (name string) { name, _ = fileAndExt(in, fpb) return } +// PathNoExt takes a path, strips out the extension, +// and returns the name of the file. +func PathNoExt(in string) string { + return strings.TrimSuffix(in, path.Ext(in)) +} + // FileAndExt returns the filename and any extension of a file path as // two separate strings. // |