diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-01-15 20:40:39 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-01-17 16:22:33 +0100 |
commit | 20c9b6ec81171d1c586ea31d5d08b40b0edaffc6 (patch) | |
tree | 990d2709c1333663dce2ff97f16f8791fef3bac9 /resource/image_test.go | |
parent | f8a119b606d55aa4f31f16e5a3cadc929c99e4f8 (diff) |
resource: Add front matter metadata to Resource
This commit expands the Resource interface with 3 new methods:
* Name
* Title
* Params
All of these can be set in the Page front matter. `Name` will get its default value from the base filename, and is the value used in the ByPrefix and GetByPrefix lookup methods.
Fixes #4244
Diffstat (limited to 'resource/image_test.go')
-rw-r--r-- | resource/image_test.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/resource/image_test.go b/resource/image_test.go index 28f68a46c..bf097b319 100644 --- a/resource/image_test.go +++ b/resource/image_test.go @@ -147,3 +147,25 @@ func TestDecodeImaging(t *testing.T) { assert.Equal(42, imaging.Quality) assert.Equal("nearestneighbor", imaging.ResampleFilter) } + +func TestImageWithMetadata(t *testing.T) { + assert := require.New(t) + + image := fetchSunset(assert) + + var meta = []map[string]interface{}{ + map[string]interface{}{ + "title": "My Sunset", + "name": "Sunset #:counter", + "src": "*.jpg", + }, + } + + assert.NoError(AssignMetadata(meta, image)) + assert.Equal("Sunset #1", image.Name()) + + resized, err := image.Resize("200x") + assert.NoError(err) + assert.Equal("Sunset #1", resized.Name()) + +} |