all: Document the Output Formats feature

This commit also adds a new command, docshelper, with some utility funcs that adds a JSON datafiles to /docs/data that would be a pain to create and maintain by hand.

Fixes #3242
This commit is contained in:
Bjørn Erik Pedersen
2017-04-05 16:18:53 +02:00
parent 9580872459
commit 3c405f5172
13 changed files with 722 additions and 153 deletions

17
media/docshelper.go Normal file
View File

@@ -0,0 +1,17 @@
package media
import (
"github.com/spf13/hugo/docshelper"
)
// This is is just some helpers used to create some JSON used in the Hugo docs.
func init() {
docsProvider := func() map[string]interface{} {
docs := make(map[string]interface{})
docs["types"] = DefaultTypes
return docs
}
docshelper.AddDocProvider("media", docsProvider)
}

View File

@@ -14,6 +14,7 @@
package media
import (
"encoding/json"
"fmt"
"sort"
"strings"
@@ -177,3 +178,16 @@ func DecodeTypes(maps ...map[string]interface{}) (Types, error) {
return m, nil
}
func (t Type) MarshalJSON() ([]byte, error) {
type Alias Type
return json.Marshal(&struct {
Type string
String string
Alias
}{
Type: t.Type(),
String: t.String(),
Alias: (Alias)(t),
})
}