Skip to content

Commit

Permalink
fix: #33 don't show empty section
Browse files Browse the repository at this point in the history
  • Loading branch information
waynezhang committed Jul 29, 2024
1 parent c55cfe0 commit 62ff944
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
4 changes: 3 additions & 1 deletion internal/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ func Build(metadata []config.SectionMetadata, option config.ExtractOption) ([]Se
}
slugs[slug] = true

sections = append(sections, s)
if len(s.ImageSets) > 0 {
sections = append(sections, s)
}
}

return sections, nil
Expand Down
14 changes: 13 additions & 1 deletion internal/indexer/indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ func TestBuildDuplicatedSlugs(t *testing.T) {
assert.NotNil(t, err)
}

func TestBuildEmptySection(t *testing.T) {
var meta config.SectionMetadata
var emptyMeta config.SectionMetadata
_ = mapstructure.Decode(testdata.Collection1, &meta)
_ = mapstructure.Decode(testdata.EmptyCollection, &emptyMeta)

data := []config.SectionMetadata{meta, emptyMeta}

sections, _ := Build(data, defaultOption)
assert.Equal(t, 1, len(sections))
assert.Equal(t, testdata.Collection1["title"], sections[0].Title)
}

func TestBuildImageSets(t *testing.T) {
expectedAscendingFileNames := []string{
testdata.Collection1FileName1,
Expand Down Expand Up @@ -89,7 +102,6 @@ func TestBuildImageSets(t *testing.T) {
sets[2].FileName,
})
}

func TestInvalidBuildImageSets(t *testing.T) {
tmp, _ := os.MkdirTemp("", "foto-test")
path := filepath.Join(tmp, "folder-not-exist")
Expand Down
11 changes: 11 additions & 0 deletions internal/testdata/testdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,17 @@ var (
Collection2FileName3 = "2023-04-29.jpg"
)

var (
EmptyCollection = map[string]interface{}{
"title": "Empty Collection",
"text": "This is an empty collection",
"slug": "empty-slug-section",
"folder": "../../testdata/empty-section",
"ascending": true,
"imageSets": []map[string]interface{}{},
}
)

var (
RotatedImageFile = "../../testdata/rotated.jpg"
RotatedImageWidth = 1440
Expand Down

0 comments on commit 62ff944

Please sign in to comment.