diff --git a/gitssg.go b/gitssg.go index f2e03c4..f70b546 100644 --- a/gitssg.go +++ b/gitssg.go @@ -27,12 +27,12 @@ type RepoDir struct { // ToDo: replace has* with the filename, as it can be bare or .md type RepoInfo struct { - Name string - Description string - Url string - HasReadme bool - HasLicense bool - HasContributing bool + Name string + Description string + Url string + Readme string + License string + Contributing string } type CommitFile struct { @@ -69,6 +69,9 @@ type CommitInfo struct { var embedTmpl embed.FS var timeShortFormatStr = "2006-01-02 15:04" var timeLongFormatStr = time.RFC1123 +var readmeNames = []string{"README", "README.md", "README.txt"} +var licenseNames = []string{"LICENSE", "LICENSE.txt"} +var contributingNames = []string{"CONTRIBUTING", "CONTRIBUTING.txt"} var funcMap = template.FuncMap{ "inc": func(i int) int { return i + 1 @@ -78,16 +81,16 @@ var funcMap = template.FuncMap{ menu += " | Files" menu += " | Refs" - if repoInfo.HasReadme { - menu += "| README" + if repoInfo.Readme != "" { + menu += " | README" } - if repoInfo.HasLicense { - menu += "| LICENSE" + if repoInfo.License != "" { + menu += " | LICENSE" } - if repoInfo.HasContributing { - menu += "| CONTRIBUTING" + if repoInfo.Contributing != "" { + menu += " | CONTRIBUTING" } return template.HTML(menu) @@ -271,7 +274,27 @@ func generateRepo(path string, logLimit int) error { return fmt.Errorf("cannot get commit for hash %s: %w", head.Hash(), err) } - // ToDo: populate hasReadme, hasLicense and hasContributing + // populate Readme, License and Contributing + for _, name := range readmeNames { + if _, err := c.File(name); err == nil { + repoInfo.Readme = name + break + } + } + + for _, name := range licenseNames { + if _, err := c.File(name); err == nil { + repoInfo.License = name + break + } + } + + for _, name := range contributingNames { + if _, err := c.File(name); err == nil { + repoInfo.Contributing = name + break + } + } tree, err := c.Tree() if err != nil {