Skip to content

godoc: add 'shallow' PageInfoMode to only show top-level directories in subdirectory listings #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions godoc/dirtrees.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ func hasThirdParty(list []DirEntry) bool {
// If filter is set, only the directory entries whose paths match the filter
// are included.
//
func (root *Directory) listing(skipRoot bool, filter func(string) bool) *DirList {
func (root *Directory) listing(mode PageInfoMode, skipRoot bool, filter func(string) bool) *DirList {
if root == nil {
return nil
}
Expand Down Expand Up @@ -362,8 +362,12 @@ func (root *Directory) listing(skipRoot bool, filter func(string) bool) *DirList
if filter != nil && !filter(d.Path) {
continue
}
depth := d.Depth - minDepth
if mode&Shallow != 0 && depth > 0 {
continue
}
var p DirEntry
p.Depth = d.Depth - minDepth
p.Depth = depth
p.Height = maxHeight - p.Depth
// the path is relative to root.Path - remove the root.Path
// prefix (the prefix should always be present but avoid
Expand Down
4 changes: 3 additions & 1 deletion godoc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func (h *handlerServer) GetPageInfo(abspath, relpath string, mode PageInfoMode,
dir = h.c.newDirectory(abspath, 2)
timestamp = time.Now()
}
info.Dirs = dir.listing(true, func(path string) bool { return h.includePath(path, mode) })
info.Dirs = dir.listing(mode, true, func(path string) bool { return h.includePath(path, mode) })

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

// modeNames defines names for each PageInfoMode flag.
Expand All @@ -370,6 +371,7 @@ var modeNames = map[string]PageInfoMode{
"src": ShowSource,
"text": NoHTML,
"flat": FlatDir,
"shallow": Shallow,
}

// generate a query string for persisting PageInfoMode between pages.
Expand Down