mirror of
https://github.com/gogs/gogs.git
synced 2025-05-31 11:42:13 +00:00
templates/repo: fix README.ipynb not rendered (#4367)
This commit is contained in:
parent
91cd350b63
commit
6ebdf91b32
2
gogs.go
2
gogs.go
@ -16,7 +16,7 @@ import (
|
|||||||
"github.com/gogits/gogs/pkg/setting"
|
"github.com/gogits/gogs/pkg/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
const APP_VER = "0.11.7.0407"
|
const APP_VER = "0.11.8.0407"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
setting.AppVer = APP_VER
|
setting.AppVer = APP_VER
|
||||||
|
@ -23,6 +23,11 @@ func IsReadmeFile(name string) bool {
|
|||||||
return strings.HasPrefix(strings.ToLower(name), "readme")
|
return strings.HasPrefix(strings.ToLower(name), "readme")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsIPythonNotebook reports whether name looks like a IPython notebook based on its extension.
|
||||||
|
func IsIPythonNotebook(name string) bool {
|
||||||
|
return strings.HasSuffix(name, ".ipynb")
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ISSUE_NAME_STYLE_NUMERIC = "numeric"
|
ISSUE_NAME_STYLE_NUMERIC = "numeric"
|
||||||
ISSUE_NAME_STYLE_ALPHANUMERIC = "alphanumeric"
|
ISSUE_NAME_STYLE_ALPHANUMERIC = "alphanumeric"
|
||||||
|
@ -33,23 +33,23 @@ const (
|
|||||||
FORKS = "repo/forks"
|
FORKS = "repo/forks"
|
||||||
)
|
)
|
||||||
|
|
||||||
func renderDirectory(ctx *context.Context, treeLink string) {
|
func renderDirectory(c *context.Context, treeLink string) {
|
||||||
tree, err := ctx.Repo.Commit.SubTree(ctx.Repo.TreePath)
|
tree, err := c.Repo.Commit.SubTree(c.Repo.TreePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.NotFoundOrServerError("Repo.Commit.SubTree", git.IsErrNotExist, err)
|
c.NotFoundOrServerError("Repo.Commit.SubTree", git.IsErrNotExist, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
entries, err := tree.ListEntries()
|
entries, err := tree.ListEntries()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(500, "ListEntries", err)
|
c.ServerError("ListEntries", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
entries.Sort()
|
entries.Sort()
|
||||||
|
|
||||||
ctx.Data["Files"], err = entries.GetCommitsInfoWithCustomConcurrency(ctx.Repo.Commit, ctx.Repo.TreePath, setting.Repository.CommitsFetchConcurrency)
|
c.Data["Files"], err = entries.GetCommitsInfoWithCustomConcurrency(c.Repo.Commit, c.Repo.TreePath, setting.Repository.CommitsFetchConcurrency)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(500, "GetCommitsInfo", err)
|
c.ServerError("GetCommitsInfoWithCustomConcurrency", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,13 +65,13 @@ func renderDirectory(ctx *context.Context, treeLink string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if readmeFile != nil {
|
if readmeFile != nil {
|
||||||
ctx.Data["RawFileLink"] = ""
|
c.Data["RawFileLink"] = ""
|
||||||
ctx.Data["ReadmeInList"] = true
|
c.Data["ReadmeInList"] = true
|
||||||
ctx.Data["ReadmeExist"] = true
|
c.Data["ReadmeExist"] = true
|
||||||
|
|
||||||
dataRc, err := readmeFile.Data()
|
dataRc, err := readmeFile.Data()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(500, "Data", err)
|
c.ServerError("readmeFile.Data", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,38 +80,41 @@ func renderDirectory(ctx *context.Context, treeLink string) {
|
|||||||
buf = buf[:n]
|
buf = buf[:n]
|
||||||
|
|
||||||
isTextFile := tool.IsTextFile(buf)
|
isTextFile := tool.IsTextFile(buf)
|
||||||
ctx.Data["IsTextFile"] = isTextFile
|
c.Data["IsTextFile"] = isTextFile
|
||||||
ctx.Data["FileName"] = readmeFile.Name()
|
c.Data["FileName"] = readmeFile.Name()
|
||||||
if isTextFile {
|
if isTextFile {
|
||||||
d, _ := ioutil.ReadAll(dataRc)
|
d, _ := ioutil.ReadAll(dataRc)
|
||||||
buf = append(buf, d...)
|
buf = append(buf, d...)
|
||||||
switch {
|
switch {
|
||||||
case markup.IsMarkdownFile(readmeFile.Name()):
|
case markup.IsMarkdownFile(readmeFile.Name()):
|
||||||
ctx.Data["IsMarkdown"] = true
|
c.Data["IsMarkdown"] = true
|
||||||
buf = markup.Markdown(buf, treeLink, ctx.Repo.Repository.ComposeMetas())
|
buf = markup.Markdown(buf, treeLink, c.Repo.Repository.ComposeMetas())
|
||||||
|
case markup.IsIPythonNotebook(readmeFile.Name()):
|
||||||
|
c.Data["IsIPythonNotebook"] = true
|
||||||
|
c.Data["RawFileLink"] = c.Repo.RepoLink + "/raw/" + path.Join(c.Repo.BranchName, c.Repo.TreePath, readmeFile.Name())
|
||||||
default:
|
default:
|
||||||
buf = bytes.Replace(buf, []byte("\n"), []byte(`<br>`), -1)
|
buf = bytes.Replace(buf, []byte("\n"), []byte(`<br>`), -1)
|
||||||
}
|
}
|
||||||
ctx.Data["FileContent"] = string(buf)
|
c.Data["FileContent"] = string(buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show latest commit info of repository in table header,
|
// Show latest commit info of repository in table header,
|
||||||
// or of directory if not in root directory.
|
// or of directory if not in root directory.
|
||||||
latestCommit := ctx.Repo.Commit
|
latestCommit := c.Repo.Commit
|
||||||
if len(ctx.Repo.TreePath) > 0 {
|
if len(c.Repo.TreePath) > 0 {
|
||||||
latestCommit, err = ctx.Repo.Commit.GetCommitByPath(ctx.Repo.TreePath)
|
latestCommit, err = c.Repo.Commit.GetCommitByPath(c.Repo.TreePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(500, "GetCommitByPath", err)
|
c.ServerError("GetCommitByPath", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctx.Data["LatestCommit"] = latestCommit
|
c.Data["LatestCommit"] = latestCommit
|
||||||
ctx.Data["LatestCommitUser"] = models.ValidateCommitWithEmail(latestCommit)
|
c.Data["LatestCommitUser"] = models.ValidateCommitWithEmail(latestCommit)
|
||||||
|
|
||||||
if ctx.Repo.CanEnableEditor() {
|
if c.Repo.CanEnableEditor() {
|
||||||
ctx.Data["CanAddFile"] = true
|
c.Data["CanAddFile"] = true
|
||||||
ctx.Data["CanUploadFile"] = setting.Repository.Upload.Enabled
|
c.Data["CanUploadFile"] = setting.Repository.Upload.Enabled
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,7 +160,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
|
|||||||
ctx.Data["IsMarkdown"] = isMarkdown
|
ctx.Data["IsMarkdown"] = isMarkdown
|
||||||
ctx.Data["ReadmeExist"] = isMarkdown && markup.IsReadmeFile(blob.Name())
|
ctx.Data["ReadmeExist"] = isMarkdown && markup.IsReadmeFile(blob.Name())
|
||||||
|
|
||||||
ctx.Data["IsIPythonNotebook"] = strings.HasSuffix(blob.Name(), ".ipynb")
|
ctx.Data["IsIPythonNotebook"] = markup.IsIPythonNotebook(blob.Name())
|
||||||
|
|
||||||
if isMarkdown {
|
if isMarkdown {
|
||||||
ctx.Data["FileContent"] = string(markup.Markdown(buf, path.Dir(treeLink), ctx.Repo.Repository.ComposeMetas()))
|
ctx.Data["FileContent"] = string(markup.Markdown(buf, path.Dir(treeLink), ctx.Repo.Repository.ComposeMetas()))
|
||||||
|
@ -1 +1 @@
|
|||||||
0.11.7.0407
|
0.11.8.0407
|
@ -47,7 +47,7 @@
|
|||||||
<link rel="stylesheet" href="{{AppSubURL}}/assets/octicons-4.3.0/octicons.min.css">
|
<link rel="stylesheet" href="{{AppSubURL}}/assets/octicons-4.3.0/octicons.min.css">
|
||||||
|
|
||||||
<!-- notebook.js for rendering ipython notebooks and marked.js for rendering markdown in notebooks -->
|
<!-- notebook.js for rendering ipython notebooks and marked.js for rendering markdown in notebooks -->
|
||||||
{{if .IsIPythonNotebook }}
|
{{if .IsIPythonNotebook}}
|
||||||
<script src="{{AppSubURL}}/plugins/notebookjs-0.2.6/notebook.min.js"></script>
|
<script src="{{AppSubURL}}/plugins/notebookjs-0.2.6/notebook.min.js"></script>
|
||||||
<script src="{{AppSubURL}}/plugins/marked-0.3.6/marked.min.js"></script>
|
<script src="{{AppSubURL}}/plugins/marked-0.3.6/marked.min.js"></script>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
@ -36,28 +36,29 @@
|
|||||||
{{end}}
|
{{end}}
|
||||||
</h4>
|
</h4>
|
||||||
<div class="ui attached table segment">
|
<div class="ui attached table segment">
|
||||||
<div id="{{if .IsIPythonNotebook}}ipython-notebook{{end}}" class="file-view {{if .IsMarkdown}}markdown{{else if .ReadmeInList}}plain-text{{else if .IsIPythonNotebook}}ipython-notebook1{{else if and .IsTextFile}}code-view{{end}} has-emoji">
|
<div id="{{if .IsIPythonNotebook}}ipython-notebook{{end}}" class="file-view {{if .IsMarkdown}}markdown{{else if .IsIPythonNotebook}}ipython-notebook{{else if .ReadmeInList}}plain-text{{else if and .IsTextFile}}code-view{{end}} has-emoji">
|
||||||
{{if or .IsMarkdown .ReadmeInList}}
|
{{if .IsMarkdown}}
|
||||||
{{if .FileContent}}{{.FileContent | Str2html}}{{end}}
|
{{if .FileContent}}{{.FileContent | Str2html}}{{end}}
|
||||||
{{else if .IsIPythonNotebook}}
|
{{else if .IsIPythonNotebook}}
|
||||||
{{if .FileContent}}
|
<script>
|
||||||
<script>
|
var rendered = null;
|
||||||
var rendered = null;
|
console.log("fuck")
|
||||||
$.getJSON("{{.RawFileLink}}", null, function(notebook_json) {
|
$.getJSON("{{.RawFileLink}}", null, function(notebook_json) {
|
||||||
var notebook = nb.parse(notebook_json);
|
var notebook = nb.parse(notebook_json);
|
||||||
rendered = notebook.render();
|
rendered = notebook.render();
|
||||||
$("#ipython-notebook").append(rendered);
|
$("#ipython-notebook").append(rendered);
|
||||||
$("#ipython-notebook code").each(function(i, block) {
|
$("#ipython-notebook code").each(function(i, block) {
|
||||||
$(block).addClass("py").addClass("python");
|
$(block).addClass("py").addClass("python");
|
||||||
hljs.highlightBlock(block);
|
hljs.highlightBlock(block);
|
||||||
});
|
|
||||||
|
|
||||||
$("#ipython-notebook .nb-markdown-cell").each(function(i, markdown) {
|
|
||||||
$(markdown).html(marked($(markdown).html()));
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
</script>
|
|
||||||
{{end}}
|
$("#ipython-notebook .nb-markdown-cell").each(function(i, markdown) {
|
||||||
|
$(markdown).html(marked($(markdown).html()));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{{else if .ReadmeInList}}
|
||||||
|
{{if .FileContent}}{{.FileContent | Str2html}}{{end}}
|
||||||
{{else if not .IsTextFile}}
|
{{else if not .IsTextFile}}
|
||||||
<div class="view-raw ui center">
|
<div class="view-raw ui center">
|
||||||
{{if .IsImageFile}}
|
{{if .IsImageFile}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user