From 57dc591b124b071cb943cca8c11e98824b65cefc Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Wed, 27 Jan 2021 15:07:00 +0100 Subject: [PATCH] Remove small words from filename title endings --- pkg/txt/file_title.go | 5 +++++ pkg/txt/file_title_test.go | 3 +++ 2 files changed, 8 insertions(+) diff --git a/pkg/txt/file_title.go b/pkg/txt/file_title.go index c77ba868a..37db36ba5 100644 --- a/pkg/txt/file_title.go +++ b/pkg/txt/file_title.go @@ -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 "" } diff --git a/pkg/txt/file_title_test.go b/pkg/txt/file_title_test.go index beb107570..73e85e859 100644 --- a/pkg/txt/file_title_test.go +++ b/pkg/txt/file_title_test.go @@ -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")) + }) }