aboutsummaryrefslogtreecommitdiffhomepage
path: root/media
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2017-04-03 17:00:23 +0200
committerBjørn Erik Pedersen <[email protected]>2017-04-04 15:12:30 +0200
commitc9aee467d387c4c3489c23f120a7ef2fed4d12df (patch)
tree4b1058db28f48f37aebf31e558292a8f5019045d /media
parentd6e8b86f66d6d505fadc32bca601762a4aa90c5e (diff)
downloadhugo-c9aee467d387c4c3489c23f120a7ef2fed4d12df.tar.gz
hugo-c9aee467d387c4c3489c23f120a7ef2fed4d12df.zip
output: Add output formats decoder
And clean up the output package.
Diffstat (limited to 'media')
-rw-r--r--media/mediaType.go10
-rw-r--r--media/mediaType_test.go11
2 files changed, 21 insertions, 0 deletions
diff --git a/media/mediaType.go b/media/mediaType.go
index a6ba873eb..b56904cd9 100644
--- a/media/mediaType.go
+++ b/media/mediaType.go
@@ -15,10 +15,20 @@ package media
import (
"fmt"
+ "strings"
)
type Types []Type
+func (t Types) GetByType(tp string) (Type, bool) {
+ for _, tt := range t {
+ if strings.EqualFold(tt.Type(), tp) {
+ return tt, true
+ }
+ }
+ return Type{}, false
+}
+
// A media type (also known as MIME type and content type) is a two-part identifier for
// file formats and format contents transmitted on the Internet.
// For Hugo's use case, we use the top-level type name / subtype name + suffix.
diff --git a/media/mediaType_test.go b/media/mediaType_test.go
index e918b9393..c97ac782a 100644
--- a/media/mediaType_test.go
+++ b/media/mediaType_test.go
@@ -47,3 +47,14 @@ func TestDefaultTypes(t *testing.T) {
}
}
+
+func TestGetByType(t *testing.T) {
+ types := Types{HTMLType, RSSType}
+
+ mt, found := types.GetByType("text/HTML")
+ require.True(t, found)
+ require.Equal(t, mt, HTMLType)
+
+ _, found = types.GetByType("text/nono")
+ require.False(t, found)
+}