mirror of
https://github.com/gohugoio/hugo.git
synced 2024-12-01 04:41:29 -05:00
parent
288be1976d
commit
943ff7f7ce
1 changed files with 38 additions and 0 deletions
|
@ -15,6 +15,7 @@ package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
@ -26,6 +27,7 @@ import (
|
||||||
"github.com/alecthomas/chroma/v2/styles"
|
"github.com/alecthomas/chroma/v2/styles"
|
||||||
"github.com/bep/simplecobra"
|
"github.com/bep/simplecobra"
|
||||||
"github.com/gohugoio/hugo/common/hugo"
|
"github.com/gohugoio/hugo/common/hugo"
|
||||||
|
"github.com/gohugoio/hugo/docshelper"
|
||||||
"github.com/gohugoio/hugo/helpers"
|
"github.com/gohugoio/hugo/helpers"
|
||||||
"github.com/gohugoio/hugo/hugofs"
|
"github.com/gohugoio/hugo/hugofs"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
@ -174,11 +176,47 @@ url: %s
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var docsHelperTarget string
|
||||||
|
|
||||||
|
newDocsHelper := func() simplecobra.Commander {
|
||||||
|
return &simpleCommand{
|
||||||
|
name: "docshelper",
|
||||||
|
short: "Generate some data files for the Hugo docs.",
|
||||||
|
|
||||||
|
run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {
|
||||||
|
r.Println("Generate docs data to", docsHelperTarget)
|
||||||
|
|
||||||
|
targetFile := filepath.Join(docsHelperTarget, "docs.json")
|
||||||
|
|
||||||
|
f, err := os.Create(targetFile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
enc := json.NewEncoder(f)
|
||||||
|
enc.SetIndent("", " ")
|
||||||
|
|
||||||
|
if err := enc.Encode(docshelper.GetDocProvider()); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
r.Println("Done!")
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
withc: func(cmd *cobra.Command) {
|
||||||
|
cmd.Hidden = true
|
||||||
|
cmd.PersistentFlags().StringVarP(&docsHelperTarget, "dir", "", "docs/data", "data dir")
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return &genCommand{
|
return &genCommand{
|
||||||
commands: []simplecobra.Commander{
|
commands: []simplecobra.Commander{
|
||||||
newChromaStyles(),
|
newChromaStyles(),
|
||||||
newGen(),
|
newGen(),
|
||||||
newMan(),
|
newMan(),
|
||||||
|
newDocsHelper(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue