mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
parent
b1b6912412
commit
d139f30234
3 changed files with 4438 additions and 6084 deletions
|
@ -14,6 +14,7 @@
|
||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -34,6 +35,7 @@ import (
|
||||||
"github.com/gohugoio/hugo/parser"
|
"github.com/gohugoio/hugo/parser"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/cobra/doc"
|
"github.com/spf13/cobra/doc"
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newGenCommand() *genCommand {
|
func newGenCommand() *genCommand {
|
||||||
|
@ -188,16 +190,8 @@ url: %s
|
||||||
run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {
|
run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {
|
||||||
r.Println("Generate docs data to", docsHelperTarget)
|
r.Println("Generate docs data to", docsHelperTarget)
|
||||||
|
|
||||||
targetFile := filepath.Join(docsHelperTarget, "docs.json")
|
var buf bytes.Buffer
|
||||||
|
jsonEnc := json.NewEncoder(&buf)
|
||||||
f, err := os.Create(targetFile)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
|
|
||||||
enc := json.NewEncoder(f)
|
|
||||||
enc.SetIndent("", " ")
|
|
||||||
|
|
||||||
configProvider := func() docshelper.DocProvider {
|
configProvider := func() docshelper.DocProvider {
|
||||||
conf := hugolib.DefaultConfig()
|
conf := hugolib.DefaultConfig()
|
||||||
|
@ -207,7 +201,25 @@ url: %s
|
||||||
}
|
}
|
||||||
|
|
||||||
docshelper.AddDocProviderFunc(configProvider)
|
docshelper.AddDocProviderFunc(configProvider)
|
||||||
if err := enc.Encode(docshelper.GetDocProvider()); err != nil {
|
if err := jsonEnc.Encode(docshelper.GetDocProvider()); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decode the JSON to a map[string]interface{} and then unmarshal it again to the correct format.
|
||||||
|
var m map[string]interface{}
|
||||||
|
if err := json.Unmarshal(buf.Bytes(), &m); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
targetFile := filepath.Join(docsHelperTarget, "docs.yaml")
|
||||||
|
|
||||||
|
f, err := os.Create(targetFile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
yamlEnc := yaml.NewEncoder(f)
|
||||||
|
if err := yamlEnc.Encode(m); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
6073
docs/data/docs.json
6073
docs/data/docs.json
File diff suppressed because it is too large
Load diff
4415
docs/data/docs.yaml
Normal file
4415
docs/data/docs.yaml
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue