@@ -95,19 +95,23 @@ func (i *item) addChild(c child) {
9595
9696var onlyGo = []string {"go" }
9797
98+ type extraFile struct { srcRelativePath , dstRelativePath , name string }
99+
98100type result struct {
99101 pages map [string ]* page
100102 toc tableOfContents
101103 module * packages.Module
102- extraFiles []string
104+ extraFiles []extraFile
103105}
104106
105107// parse parses the directory into a map of import path -> page and a TOC.
106108//
107109// glob is the path to parse, usually ending in `...`. glob is passed directly
108110// to packages.Load as-is.
109111//
110- // extraFiles is a list of paths relative to the module root to include.
112+ // workingDir is the directory to use to run go commands.
113+ //
114+ // optionalExtraFiles is a list of paths relative to the module root to include.
111115func parse (glob string , workingDir string , optionalExtraFiles []string ) (* result , error ) {
112116 pages := map [string ]* page {}
113117
@@ -119,10 +123,22 @@ func parse(glob string, workingDir string, optionalExtraFiles []string) (*result
119123
120124 // Filter out extra files that don't exist because some modules don't have a
121125 // README.
122- extraFiles := []string {}
126+ extraFiles := []extraFile {}
123127 for _ , f := range optionalExtraFiles {
124128 if _ , err := os .Stat (filepath .Join (module .Dir , f )); err == nil {
125- extraFiles = append (extraFiles , f )
129+ dst := f
130+ dir := filepath .Dir (f )
131+ base := filepath .Base (f )
132+ name := strings .TrimSuffix (base , filepath .Ext (base ))
133+ name = strings .Title (name )
134+ if name == "README" {
135+ dst = filepath .Join (dir , "pkg-readme.md" )
136+ }
137+ extraFiles = append (extraFiles , extraFile {
138+ srcRelativePath : f ,
139+ dstRelativePath : dst ,
140+ name : name ,
141+ })
126142 }
127143 }
128144
@@ -317,20 +333,17 @@ func processExamples(exs []*doc.Example, fset *token.FileSet) []example {
317333 return result
318334}
319335
320- func buildTOC (mod string , pis []pkgInfo , extraFiles []string ) tableOfContents {
336+ func buildTOC (mod string , pis []pkgInfo , extraFiles []extraFile ) tableOfContents {
321337 toc := tableOfContents {}
322338
323339 modTOC := & tocItem {
324340 UID : mod , // Assume the module root has a package.
325341 Name : mod ,
326342 }
327- for _ , path := range extraFiles {
328- base := filepath .Base (path )
329- name := strings .TrimSuffix (base , filepath .Ext (base ))
330- name = strings .Title (name )
343+ for _ , ef := range extraFiles {
331344 modTOC .addItem (& tocItem {
332- Href : path ,
333- Name : name ,
345+ Href : ef . dstRelativePath ,
346+ Name : ef . name ,
334347 })
335348 }
336349
0 commit comments