Skip to content

Commit 2f5c307

Browse files
committed
godoc: add 'shallow' PageInfoMode to only show top-level directories in subdirectory listings
1 parent 677d2ff commit 2f5c307

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

godoc/dirtrees.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ func hasThirdParty(list []DirEntry) bool {
332332
// If filter is set, only the directory entries whose paths match the filter
333333
// are included.
334334
//
335-
func (root *Directory) listing(skipRoot bool, filter func(string) bool) *DirList {
335+
func (root *Directory) listing(mode PageInfoMode, skipRoot bool, filter func(string) bool) *DirList {
336336
if root == nil {
337337
return nil
338338
}
@@ -362,8 +362,12 @@ func (root *Directory) listing(skipRoot bool, filter func(string) bool) *DirList
362362
if filter != nil && !filter(d.Path) {
363363
continue
364364
}
365+
depth := d.Depth - minDepth
366+
if mode&Shallow != 0 && depth > 0 {
367+
continue
368+
}
365369
var p DirEntry
366-
p.Depth = d.Depth - minDepth
370+
p.Depth = depth
367371
p.Height = maxHeight - p.Depth
368372
// the path is relative to root.Path - remove the root.Path
369373
// prefix (the prefix should always be present but avoid

godoc/server.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func (h *handlerServer) GetPageInfo(abspath, relpath string, mode PageInfoMode,
216216
dir = h.c.newDirectory(abspath, 2)
217217
timestamp = time.Now()
218218
}
219-
info.Dirs = dir.listing(true, func(path string) bool { return h.includePath(path, mode) })
219+
info.Dirs = dir.listing(mode, true, func(path string) bool { return h.includePath(path, mode) })
220220

221221
info.DirTime = timestamp
222222
info.DirFlat = mode&FlatDir != 0
@@ -361,6 +361,7 @@ const (
361361
NoHTML // show result in textual form, do not generate HTML
362362
FlatDir // show directory in a flat (non-indented) manner
363363
NoTypeAssoc // don't associate consts, vars, and factory functions with types
364+
Shallow // don't show directories under subdirectories.
364365
)
365366

366367
// modeNames defines names for each PageInfoMode flag.
@@ -370,6 +371,7 @@ var modeNames = map[string]PageInfoMode{
370371
"src": ShowSource,
371372
"text": NoHTML,
372373
"flat": FlatDir,
374+
"shallow": Shallow,
373375
}
374376

375377
// generate a query string for persisting PageInfoMode between pages.

0 commit comments

Comments
 (0)