Skip to content

Commit

Permalink
cmd docs: add frontmatter metadata
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
  • Loading branch information
aluzzardi committed Jun 9, 2021
1 parent de3ffe0 commit b53e213
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions cmd/dagger/cmd/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io/fs"
"os"
"path"
"path/filepath"
"strings"
"text/tabwriter"
"unicode/utf8"
Expand Down Expand Up @@ -107,7 +108,7 @@ func init() {
}

func mdEscape(s string) string {
escape := []string{"<", ">"}
escape := []string{"|", "<", ">"}
for _, c := range escape {
s = strings.ReplaceAll(s, c, `\`+c)
}
Expand Down Expand Up @@ -164,7 +165,7 @@ func printValuesMarkdown(iw io.Writer, libName string, values []*compiler.Value)
fmt.Fprintf(w, "| Name\t| Type\t| Description \t|\n")
fmt.Fprintf(w, "| -------------\t|:-------------:\t|:-------------:\t|\n")
for _, i := range values {
fmt.Fprintf(w, "|*%s*\t|``%s``\t|%s\t|\n",
fmt.Fprintf(w, "|*%s*\t| `%s`\t|%s\t|\n",
formatLabel(libName, i),
mdEscape(common.FormatValue(i)),
mdEscape(common.ValueDocOneLine(i)))
Expand Down Expand Up @@ -202,7 +203,10 @@ func PrintDoc(ctx context.Context, w io.Writer, packageName string, val *compile
fmt.Fprintf(w, "Package %s\n", packageName)
fmt.Fprintf(w, "\n%s\n", common.ValueDocFull(val))
case markdownFormat:
fmt.Fprintf(w, "# Package %s\n", mdEscape(packageName))
fmt.Fprintf(w, "---\nsidebar_label: %s\n---\n\n",
filepath.Base(packageName),
)
fmt.Fprintf(w, "# %s\n", mdEscape(packageName))
comment := common.ValueDocFull(val)
if comment == "-" {
break
Expand Down Expand Up @@ -331,7 +335,7 @@ func walkStdlib(ctx context.Context, output, format string) {

pkg := fmt.Sprintf("dagger.io/%s", p)
lg.Info().Str("package", pkg).Str("format", format).Msg("generating doc")
val, err := loadCode(fmt.Sprintf("dagger.io/%s", p))
val, err := loadCode(pkg)
if err != nil {
if strings.Contains(err.Error(), "no CUE files") {
lg.Warn().Str("package", p).Err(err).Msg("ignoring")
Expand All @@ -340,7 +344,7 @@ func walkStdlib(ctx context.Context, output, format string) {
return err
}

PrintDoc(ctx, f, p, val, format)
PrintDoc(ctx, f, pkg, val, format)
return nil
})

Expand Down

0 comments on commit b53e213

Please sign in to comment.