Prepend Docusorus front matter to auto-gen CLI commands (#713)

* Pre-pend dark to auto-gen CLI commands

* After `gofmt -s`

* Update src/cmd/mdgen/mdgen.go

Co-authored-by: Keepers <ryanfkeepers@gmail.com>

* More gofmt

Co-authored-by: Keepers <ryanfkeepers@gmail.com>
This commit is contained in:
Georgi Matev 2022-08-31 18:56:05 -04:00 committed by GitHub
parent 8ead744e9f
commit dcbfed15df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,6 +3,7 @@ package main
import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/pkg/errors"
@ -26,6 +27,12 @@ var cmd = &cobra.Command{
Run: genDocs,
}
const fmTemplate = `---
title: "%s"
hide_title: true
---
`
func main() {
cmd.
PersistentFlags().
@ -41,11 +48,22 @@ func main() {
}
func genDocs(cmd *cobra.Command, args []string) {
identity := func(s string) string { return s }
filePrepender := func(filename string) string {
name := filepath.Base(filename)
base := strings.TrimSuffix(name, filepath.Ext(name))
return fmt.Sprintf(fmTemplate, strings.Replace(base, "_", " ", -1))
}
if err := makeDir(cliMarkdownDir); err != nil {
fatal(errors.Wrap(err, "preparing directory for markdown generation"))
}
err := doc.GenMarkdownTree(cli.CorsoCommand(), cliMarkdownDir)
corsoCmd := cli.CorsoCommand()
corsoCmd.DisableAutoGenTag = true
err := doc.GenMarkdownTreeCustom(corsoCmd, cliMarkdownDir, filePrepender, identity)
if err != nil {
fatal(errors.Wrap(err, "generating the Corso CLI markdown"))
}