knotserver: return README files from tree pages #581

We have README files displayed on the main page of a repository, but we don't do that on subfolders. The first step in making those available is returning README files when they exist

Signed-off-by: Skyler Grey minion@freshlybakedca.ke

Changed files
+25 -10
knotserver
types
+18 -5
knotserver/handler.go
··· 239 239 return 240 240 } 241 241 242 + var readmeContent string 243 + var readmeFile string 244 + for _, readme := range h.c.Repo.Readme { 245 + maybeReadmeFile, _ := securejoin.SecureJoin(treePath, readme) 246 + content, _ := gr.FileContent(maybeReadmeFile) 247 + if len(content) > 0 { 248 + readmeContent = string(content) 249 + readmeFile = maybeReadmeFile 250 + } 251 + } 252 + 242 253 resp := types.RepoTreeResponse{ 243 - Ref: ref, 244 - Parent: treePath, 245 - Description: getDescription(path), 246 - DotDot: filepath.Dir(treePath), 247 - Files: files, 254 + Ref: ref, 255 + Parent: treePath, 256 + Description: getDescription(path), 257 + DotDot: filepath.Dir(treePath), 258 + Files: files, 259 + Readme: readmeContent, 260 + ReadmeFileName: readmeFile, 248 261 } 249 262 250 263 writeJSON(w, resp)
+7 -5
types/repo.go
··· 41 41 } 42 42 43 43 type RepoTreeResponse struct { 44 - Ref string `json:"ref,omitempty"` 45 - Parent string `json:"parent,omitempty"` 46 - Description string `json:"description,omitempty"` 47 - DotDot string `json:"dotdot,omitempty"` 48 - Files []NiceTree `json:"files,omitempty"` 44 + Ref string `json:"ref,omitempty"` 45 + Parent string `json:"parent,omitempty"` 46 + Description string `json:"description,omitempty"` 47 + DotDot string `json:"dotdot,omitempty"` 48 + Files []NiceTree `json:"files,omitempty"` 49 + Readme string `json:"readme,omitempty"` 50 + ReadmeFileName string `json:"readme_file_name,omitempty"` 49 51 } 50 52 51 53 type TagReference struct {