package main import ( "fmt" "html" "net/http" "net/url" "strings" ) func (this *Application) Homepage(w http.ResponseWriter, r *http.Request) { this.reposMut.RLock() defer this.reposMut.RUnlock() if len(this.reposCache) == 0 { // We haven't loaded the repositories from Gitea yet this.Delay(w, r) return } // Ready for template this.Templatepage(w, r, "", "", func() { fmt.Fprint(w, ` `+this.cfg.Template.HomepageHeaderHTML+`

Projects (`+fmt.Sprintf("%d", len(this.reposCache))+`)

`) for repoIdx, repo := range this.reposCache { pageHref := html.EscapeString(`/` + url.PathEscape(repo.Name)) normalisedDesc := repo.Description normalisedDesc = strings.TrimRight(repo.Description, `.`) if len(normalisedDesc) > 0 { // Lowercase the first letter of the description, unless it starts with an acronym (all letters uppercase first word) or CamelCase word firstWord := strings.SplitN(normalisedDesc, " ", 2)[0] isAcronymOrCamelCase := len(firstWord) > 1 && (firstWord[1:] != strings.ToLower(firstWord[1:])) if !(isAcronymOrCamelCase || firstWord == `Go`) { normalisedDesc = strings.ToLower(normalisedDesc[0:1]) + normalisedDesc[1:] } // Add leading `` to separate from the repo title normalisedDesc = `, ` + normalisedDesc } rowClass := "" for _, topic := range repo.Topics { rowClass += `taggedWith-` + topic + ` ` } fmt.Fprint(w, ` `) } fmt.Fprint(w, `
`+html.EscapeString(repo.Name)+``+html.EscapeString(normalisedDesc)+` more...
`) for _, topic := range repo.Topics { fmt.Fprint(w, ``+html.EscapeString(topic)+` `) } fmt.Fprint(w, `
`) }) }