summaryrefslogtreecommitdiffhomepage
path: root/output
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2017-03-08 13:45:33 +0100
committerBjørn Erik Pedersen <[email protected]>2017-03-27 15:43:56 +0200
commitc8fff9501d424882a42f750800d9982ec47df640 (patch)
tree03b49241a12ddcf98212959b8e3c7f954ae94685 /output
parent3ec5fc35043639e7592819014180666b1a8e926b (diff)
downloadhugo-c8fff9501d424882a42f750800d9982ec47df640.tar.gz
hugo-c8fff9501d424882a42f750800d9982ec47df640.zip
Implement the first generic JSON output testcase
Diffstat (limited to 'output')
-rw-r--r--output/outputType.go55
-rw-r--r--output/outputType_test.go9
2 files changed, 64 insertions, 0 deletions
diff --git a/output/outputType.go b/output/outputType.go
index cf5fff76e..e3df96f0b 100644
--- a/output/outputType.go
+++ b/output/outputType.go
@@ -14,16 +14,40 @@
package output
import (
+ "fmt"
+ "strings"
+
"github.com/spf13/hugo/media"
)
var (
+ // An ordered list of built-in output formats
+ // See https://www.ampproject.org/learn/overview/
+ AMPType = Type{
+ Name: "AMP",
+ MediaType: media.HTMLType,
+ BaseName: "index",
+ }
+
+ CSSType = Type{
+ Name: "CSS",
+ MediaType: media.CSSType,
+ BaseName: "styles",
+ }
+
HTMLType = Type{
Name: "HTML",
MediaType: media.HTMLType,
BaseName: "index",
}
+ JSONType = Type{
+ Name: "JSON",
+ MediaType: media.HTMLType,
+ BaseName: "index",
+ IsPlainText: true,
+ }
+
RSSType = Type{
Name: "RSS",
MediaType: media.RSSType,
@@ -31,6 +55,14 @@ var (
}
)
+var builtInTypes = map[string]Type{
+ strings.ToLower(AMPType.Name): AMPType,
+ strings.ToLower(CSSType.Name): CSSType,
+ strings.ToLower(HTMLType.Name): HTMLType,
+ strings.ToLower(JSONType.Name): JSONType,
+ strings.ToLower(RSSType.Name): RSSType,
+}
+
type Types []Type
// Type represents an output represenation, usually to a file on disk.
@@ -57,3 +89,26 @@ type Type struct {
// Enable to ignore the global uglyURLs setting.
NoUgly bool
}
+
+func GetType(key string) (Type, bool) {
+ found, ok := builtInTypes[key]
+ if !ok {
+ found, ok = builtInTypes[strings.ToLower(key)]
+ }
+ return found, ok
+}
+
+// TODO(bep) outputs rewamp on global config?
+func GetTypes(keys ...string) (Types, error) {
+ var types []Type
+
+ for _, key := range keys {
+ tpe, ok := GetType(key)
+ if !ok {
+ return types, fmt.Errorf("OutputType with key %q not found", key)
+ }
+ types = append(types, tpe)
+ }
+
+ return types, nil
+}
diff --git a/output/outputType_test.go b/output/outputType_test.go
index 6f84c93d3..a55b9a81a 100644
--- a/output/outputType_test.go
+++ b/output/outputType_test.go
@@ -31,3 +31,12 @@ func TestDefaultTypes(t *testing.T) {
require.Empty(t, RSSType.Path)
require.False(t, RSSType.IsPlainText)
}
+
+func TestGetType(t *testing.T) {
+ tp, _ := GetType("html")
+ require.Equal(t, HTMLType, tp)
+ tp, _ = GetType("HTML")
+ require.Equal(t, HTMLType, tp)
+ _, found := GetType("FOO")
+ require.False(t, found)
+}