Browse Source

Merge pull request #300 from nuss-justin/issue/259

Fix issue #259. Allow links in the repository description
for-closed-social
无闻 10 years ago
parent
commit
5bbd5be0ca
2 changed files with 19 additions and 2 deletions
  1. +18
    -1
      models/repo.go
  2. +1
    -1
      templates/repo/nav.tmpl

+ 18
- 1
models/repo.go View File

@ -8,9 +8,12 @@ import (
"errors"
"fmt"
"io/ioutil"
"html"
"html/template"
"os"
"path"
"path/filepath"
"regexp"
"runtime"
"sort"
"strings"
@ -46,6 +49,10 @@ var (
LanguageIgns, Licenses []string
)
var (
DescriptionPattern = regexp.MustCompile(`https?://\S+`)
)
// getAssetList returns corresponding asset list in 'conf'.
func getAssetList(prefix string) []string {
assets := make([]string, 0, 15)
@ -145,6 +152,16 @@ func (repo *Repository) GetOwner() (err error) {
return err
}
func (repo *Repository) DescriptionHtml() template.HTML {
sanitize := func(s string) string {
// TODO(nuss-justin): Improve sanitization. Strip all tags?
ss := html.EscapeString(s)
return fmt.Sprintf(`<a href="%s" target="_blank">%s</a>`, ss, ss)
}
return template.HTML(DescriptionPattern.ReplaceAllStringFunc(repo.Description, sanitize))
}
// IsRepositoryExist returns true if the repository with given name under user has already existed.
func IsRepositoryExist(u *User, repoName string) (bool, error) {
repo := Repository{OwnerId: u.Id}
@ -1000,4 +1017,4 @@ func IsWatching(uid, rid int64) bool {
func ForkRepository(repoName string, uid int64) {
}
}

+ 1
- 1
templates/repo/nav.tmpl View File

@ -3,7 +3,7 @@
<div class="row">
<div class="col-md-7">
<h3 class="name"><i class="fa fa-book fa-lg"></i><a href="{{.Owner.HomeLink}}">{{.Owner.Name}}</a> / <a href="/{{.Owner.Name}}/{{.Repository.Name}}">{{.Repository.Name}}</a> {{if .Repository.IsPrivate}}<span class="label label-default">Private</span>{{else if .Repository.IsMirror}}<span class="label label-default">Mirror</span>{{end}}</h3>
<p class="desc">{{.Repository.Description}}{{if .Repository.Website}} <a href="{{.Repository.Website}}">{{.Repository.Website}}</a>{{end}}</p>
<p class="desc">{{.Repository.DescriptionHtml}}{{if .Repository.Website}} <a href="{{.Repository.Website}}">{{.Repository.Website}}</a>{{end}}</p>
</div>
<div class="col-md-5 actions text-right clone-group-btn">
{{if not .IsBareRepo}}

Loading…
Cancel
Save