@@ -26,6 +26,7 @@ import (
2626 "go/printer"
2727 "go/token"
2828 "log"
29+ "os"
2930 "path/filepath"
3031 "sort"
3132 "strings"
@@ -95,9 +96,10 @@ func (i *item) addChild(c child) {
9596var onlyGo = []string {"go" }
9697
9798type result struct {
98- pages map [string ]* page
99- toc tableOfContents
100- module * packages.Module
99+ pages map [string ]* page
100+ toc tableOfContents
101+ module * packages.Module
102+ extraFiles []string
101103}
102104
103105// parse parses the directory into a map of import path -> page and a TOC.
@@ -106,7 +108,7 @@ type result struct {
106108// to packages.Load as-is.
107109//
108110// extraFiles is a list of paths relative to the module root to include.
109- func parse (glob string , extraFiles []string ) (* result , error ) {
111+ func parse (glob string , optionalExtraFiles []string ) (* result , error ) {
110112 config := & packages.Config {
111113 Mode : packages .NeedName | packages .NeedSyntax | packages .NeedTypes | packages .NeedTypesInfo | packages .NeedModule ,
112114 Tests : true ,
@@ -138,6 +140,7 @@ func parse(glob string, extraFiles []string) (*result, error) {
138140 // The uncompiled test package shows up as "foo_test [foo.test]".
139141 if strings .HasSuffix (id , ".test" ) ||
140142 strings .Contains (id , "internal" ) ||
143+ strings .Contains (id , "third_party" ) ||
141144 (strings .Contains (id , " [" ) && ! strings .Contains (id , "_test [" )) {
142145 continue
143146 }
@@ -176,6 +179,15 @@ func parse(glob string, extraFiles []string) (*result, error) {
176179 }
177180 sort .Strings (pkgNames )
178181
182+ // Filter out extra files that don't exist because some modules don't have a
183+ // README.
184+ extraFiles := []string {}
185+ for _ , f := range optionalExtraFiles {
186+ if _ , err := os .Stat (filepath .Join (module .Dir , f )); err == nil {
187+ extraFiles = append (extraFiles , f )
188+ }
189+ }
190+
179191 toc := buildTOC (module .Path , pkgNames , extraFiles )
180192
181193 // Once the files are grouped by package, process each package
@@ -353,9 +365,10 @@ func parse(glob string, extraFiles []string) (*result, error) {
353365 }
354366
355367 return & result {
356- pages : pages ,
357- toc : toc ,
358- module : module ,
368+ pages : pages ,
369+ toc : toc ,
370+ module : module ,
371+ extraFiles : extraFiles ,
359372 }, nil
360373}
361374
0 commit comments