mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-25 01:39:31 +00:00
Merge branch 'dev' of github.com:gogits/gogs into dev
This commit is contained in:
commit
e0a2d23baf
|
@ -6,6 +6,7 @@ package repo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -14,12 +15,30 @@ import (
|
||||||
"github.com/gogits/gogs/modules/base"
|
"github.com/gogits/gogs/modules/base"
|
||||||
"github.com/gogits/gogs/modules/git"
|
"github.com/gogits/gogs/modules/git"
|
||||||
"github.com/gogits/gogs/modules/middleware"
|
"github.com/gogits/gogs/modules/middleware"
|
||||||
|
|
||||||
|
"code.google.com/p/mahonia"
|
||||||
|
"github.com/saintfish/chardet"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
HOME base.TplName = "repo/home"
|
HOME base.TplName = "repo/home"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func toUtf8(content []byte) (error, string) {
|
||||||
|
detector := chardet.NewTextDetector()
|
||||||
|
result, err := detector.DetectBest(content)
|
||||||
|
if err != nil {
|
||||||
|
return err, ""
|
||||||
|
}
|
||||||
|
|
||||||
|
if result.Charset == "utf8" {
|
||||||
|
return nil, string(content)
|
||||||
|
}
|
||||||
|
|
||||||
|
decoder := mahonia.NewDecoder(result.Charset)
|
||||||
|
return nil, decoder.ConvertString(string(content))
|
||||||
|
}
|
||||||
|
|
||||||
func Home(ctx *middleware.Context) {
|
func Home(ctx *middleware.Context) {
|
||||||
ctx.Data["Title"] = ctx.Repo.Repository.Name
|
ctx.Data["Title"] = ctx.Repo.Repository.Name
|
||||||
|
|
||||||
|
@ -98,7 +117,12 @@ func Home(ctx *middleware.Context) {
|
||||||
if readmeExist {
|
if readmeExist {
|
||||||
ctx.Data["FileContent"] = string(base.RenderMarkdown(buf, ""))
|
ctx.Data["FileContent"] = string(base.RenderMarkdown(buf, ""))
|
||||||
} else {
|
} else {
|
||||||
|
if err, content := toUtf8(buf); err != nil {
|
||||||
|
fmt.Println("transfer encode error:", err)
|
||||||
ctx.Data["FileContent"] = string(buf)
|
ctx.Data["FileContent"] = string(buf)
|
||||||
|
} else {
|
||||||
|
ctx.Data["FileContent"] = content
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue