Skip to content

Commit

Permalink
fix depth problem
Browse files Browse the repository at this point in the history
  • Loading branch information
bughou committed Jul 11, 2020
1 parent 18a4eac commit d5f83b0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
13 changes: 8 additions & 5 deletions docs/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (g *Group) Child(path, fullPath string, descs []string) Group {
title += " (" + fullPath + ")"
child.CreateReadme(title, descs[1:])
}
g.LinkInReadme(child.depth, title, path)
g.LinkInReadme(title, path)
}
return child
}
Expand All @@ -61,7 +61,7 @@ func (g *Group) Route(method, path, fullPath string, handler interface{}) {
log.Panic(err)
}

g.LinkInReadme(g.depth+1, route.Title(method, fullPath), path)
g.LinkInReadme(route.Title(method, fullPath), path)
}

func (g *Group) CreateReadme(title string, descs []string) {
Expand All @@ -76,12 +76,15 @@ func (g *Group) CreateReadme(title string, descs []string) {
}
}

func (g *Group) LinkInReadme(depth int, title, href string) {
func (g *Group) LinkInReadme(title, href string) {
buf := bytes.NewBufferString("##")
if depth >= 2 {
buf.WriteString(strings.Repeat("#", depth-1))
if g.depth > 0 {
buf.WriteString(strings.Repeat("#", g.depth))
}
buf.WriteString(" ")
if g.depth > 0 {
buf.WriteString(strings.Repeat(" ", g.depth)) // use a full-width space
}

switch href {
case ".", "/":
Expand Down
5 changes: 4 additions & 1 deletion docs/z_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ func ExampleGroup() {
router := goa.New()
router.DocDir(filepath.Join(fs.SourceDir(), "testdata"))

router.Group("/accounts", "账号", "用户、公司、员工、角色、权限")
accounts := router.Group("/", "账号", "用户、公司、员工、角色、权限")
accounts.Group("/users", "用户")
accounts.Group("/companies", "公司")

router.Group("/goods", "商品")
router.Group("/bill", "单据", "采购、销售")
router.Group("/storage", "库存")
Expand Down

0 comments on commit d5f83b0

Please sign in to comment.