|
|
|
@ -518,15 +518,11 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
|
|
|
|
|
status = status.Or(statuses[i])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ansiContent, _, _ := highlight.AnsiFile(blob.Name(), language, buf)
|
|
|
|
|
log.Info("%s", ansiContent[0])
|
|
|
|
|
tks, _ := parser.Parse(strings.Join(ansiContent, ""))
|
|
|
|
|
imgStr, err := image.Draw(tks)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Error("Drawing image failed: %v", err)
|
|
|
|
|
ogImg := ctx.Repo.Repository.HTMLURL() + "/src/og/" + ctx.Repo.BranchName
|
|
|
|
|
if len(ctx.Repo.TreePath) > 0 {
|
|
|
|
|
ogImg += "/" + util.PathEscapeSegments(ctx.Repo.TreePath)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ctx.Data["OgImage"] = imgStr
|
|
|
|
|
ctx.Data["OgImage"] = ogImg
|
|
|
|
|
ctx.Data["EscapeStatus"] = status
|
|
|
|
|
ctx.Data["FileContent"] = fileContent
|
|
|
|
|
ctx.Data["LineEscapeStatus"] = statuses
|
|
|
|
@ -717,6 +713,55 @@ func checkCitationFile(ctx *context.Context, entry *git.TreeEntry) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func OgImage(ctx *context.Context) {
|
|
|
|
|
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(ctx.Repo.TreePath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Error("%v", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
blob := entry.Blob()
|
|
|
|
|
buf, dataRc, _, err := getFileReader(ctx.Repo.Repository.ID, blob)
|
|
|
|
|
if err != nil {
|
|
|
|
|
ctx.ServerError("getFileReader", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
defer dataRc.Close()
|
|
|
|
|
|
|
|
|
|
language := ""
|
|
|
|
|
indexFilename, worktree, deleteTemporaryFile, err := ctx.Repo.GitRepo.ReadTreeToTemporaryIndex(ctx.Repo.CommitID)
|
|
|
|
|
if err == nil {
|
|
|
|
|
defer deleteTemporaryFile()
|
|
|
|
|
filename2attribute2info, err := ctx.Repo.GitRepo.CheckAttribute(git.CheckAttributeOpts{
|
|
|
|
|
CachedOnly: true,
|
|
|
|
|
Attributes: []string{"linguist-language", "gitlab-language"},
|
|
|
|
|
Filenames: []string{ctx.Repo.TreePath},
|
|
|
|
|
IndexFile: indexFilename,
|
|
|
|
|
WorkTree: worktree,
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Error("Unable to load attributes for %-v:%s. Error: %v", ctx.Repo.Repository, ctx.Repo.TreePath, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
language = filename2attribute2info[ctx.Repo.TreePath]["linguist-language"]
|
|
|
|
|
if language == "" || language == "unspecified" {
|
|
|
|
|
language = filename2attribute2info[ctx.Repo.TreePath]["gitlab-language"]
|
|
|
|
|
}
|
|
|
|
|
if language == "unspecified" {
|
|
|
|
|
language = ""
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ansiContent, _, _ := highlight.AnsiFile(blob.Name(), language, buf)
|
|
|
|
|
log.Info("%s", ansiContent[0])
|
|
|
|
|
tks, _ := parser.Parse(strings.Join(ansiContent, ""))
|
|
|
|
|
img, err := image.Draw(tks)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Error("Drawing image failed: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ctx.Write(img)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Home render repository home page
|
|
|
|
|
func Home(ctx *context.Context) {
|
|
|
|
|
if setting.Other.EnableFeed {
|
|
|
|
|