From 3c405f5172a6081483c9e5f4264a4d60e60bc8ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Wed, 5 Apr 2017 16:18:53 +0200 Subject: 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 --- media/docshelper.go | 17 +++++++++++++++++ media/mediaType.go | 14 ++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 media/docshelper.go (limited to 'media') diff --git a/media/docshelper.go b/media/docshelper.go new file mode 100644 index 000000000..9a84d5c7f --- /dev/null +++ b/media/docshelper.go @@ -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) +} diff --git a/media/mediaType.go b/media/mediaType.go index 942e9070e..6b6f90439 100644 --- a/media/mediaType.go +++ b/media/mediaType.go @@ -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), + }) +} -- cgit v1.2.3