Skip to content

Commit

Permalink
Remove small words from filename title endings
Browse files Browse the repository at this point in the history
  • Loading branch information
lastzero committed Jan 27, 2021
1 parent b98c87d commit 57dc591
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/txt/file_title.go
Expand Up @@ -56,6 +56,11 @@ func FileTitle(s string) string {
title = strings.ReplaceAll(title, "-", " ")
title = strings.ReplaceAll(title, " ", " ")

// Remove small words from title ending.
for w, _ := range SmallWords {
title = strings.TrimSuffix(title, " "+w)
}

if len(title) <= 4 && IsASCII(title) {
return ""
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/txt/file_title_test.go
Expand Up @@ -107,4 +107,7 @@ func TestFileTitle(t *testing.T) {
t.Run("NewYears", func(t *testing.T) {
assert.Equal(t, "Boston New Year's", FileTitle("boston new year's"))
})
t.Run("Screenshot", func(t *testing.T) {
assert.Equal(t, "Screenshot", FileTitle("Screenshot 2020-05-04 at 14:25:01.jpeg"))
})
}

0 comments on commit 57dc591

Please sign in to comment.