@@ -33,23 +33,23 @@ const (
33
33
FORKS = "repo/forks"
34
34
)
35
35
36
- func renderDirectory (ctx * context.Context , treeLink string ) {
37
- tree , err := ctx .Repo .Commit .SubTree (ctx .Repo .TreePath )
36
+ func renderDirectory (c * context.Context , treeLink string ) {
37
+ tree , err := c .Repo .Commit .SubTree (c .Repo .TreePath )
38
38
if err != nil {
39
- ctx .NotFoundOrServerError ("Repo.Commit.SubTree" , git .IsErrNotExist , err )
39
+ c .NotFoundOrServerError ("Repo.Commit.SubTree" , git .IsErrNotExist , err )
40
40
return
41
41
}
42
42
43
43
entries , err := tree .ListEntries ()
44
44
if err != nil {
45
- ctx . Handle ( 500 , "ListEntries" , err )
45
+ c . ServerError ( "ListEntries" , err )
46
46
return
47
47
}
48
48
entries .Sort ()
49
49
50
- ctx .Data ["Files" ], err = entries .GetCommitsInfoWithCustomConcurrency (ctx .Repo .Commit , ctx .Repo .TreePath , setting .Repository .CommitsFetchConcurrency )
50
+ c .Data ["Files" ], err = entries .GetCommitsInfoWithCustomConcurrency (c .Repo .Commit , c .Repo .TreePath , setting .Repository .CommitsFetchConcurrency )
51
51
if err != nil {
52
- ctx . Handle ( 500 , "GetCommitsInfo " , err )
52
+ c . ServerError ( "GetCommitsInfoWithCustomConcurrency " , err )
53
53
return
54
54
}
55
55
@@ -65,13 +65,13 @@ func renderDirectory(ctx *context.Context, treeLink string) {
65
65
}
66
66
67
67
if readmeFile != nil {
68
- ctx .Data ["RawFileLink" ] = ""
69
- ctx .Data ["ReadmeInList" ] = true
70
- ctx .Data ["ReadmeExist" ] = true
68
+ c .Data ["RawFileLink" ] = ""
69
+ c .Data ["ReadmeInList" ] = true
70
+ c .Data ["ReadmeExist" ] = true
71
71
72
72
dataRc , err := readmeFile .Data ()
73
73
if err != nil {
74
- ctx . Handle ( 500 , " Data" , err )
74
+ c . ServerError ( "readmeFile. Data" , err )
75
75
return
76
76
}
77
77
@@ -80,38 +80,41 @@ func renderDirectory(ctx *context.Context, treeLink string) {
80
80
buf = buf [:n ]
81
81
82
82
isTextFile := tool .IsTextFile (buf )
83
- ctx .Data ["IsTextFile" ] = isTextFile
84
- ctx .Data ["FileName" ] = readmeFile .Name ()
83
+ c .Data ["IsTextFile" ] = isTextFile
84
+ c .Data ["FileName" ] = readmeFile .Name ()
85
85
if isTextFile {
86
86
d , _ := ioutil .ReadAll (dataRc )
87
87
buf = append (buf , d ... )
88
88
switch {
89
89
case markup .IsMarkdownFile (readmeFile .Name ()):
90
- ctx .Data ["IsMarkdown" ] = true
91
- buf = markup .Markdown (buf , treeLink , ctx .Repo .Repository .ComposeMetas ())
90
+ c .Data ["IsMarkdown" ] = true
91
+ buf = markup .Markdown (buf , treeLink , c .Repo .Repository .ComposeMetas ())
92
+ case markup .IsIPythonNotebook (readmeFile .Name ()):
93
+ c .Data ["IsIPythonNotebook" ] = true
94
+ c .Data ["RawFileLink" ] = c .Repo .RepoLink + "/raw/" + path .Join (c .Repo .BranchName , c .Repo .TreePath , readmeFile .Name ())
92
95
default :
93
96
buf = bytes .Replace (buf , []byte ("\n " ), []byte (`<br>` ), - 1 )
94
97
}
95
- ctx .Data ["FileContent" ] = string (buf )
98
+ c .Data ["FileContent" ] = string (buf )
96
99
}
97
100
}
98
101
99
102
// Show latest commit info of repository in table header,
100
103
// or of directory if not in root directory.
101
- latestCommit := ctx .Repo .Commit
102
- if len (ctx .Repo .TreePath ) > 0 {
103
- latestCommit , err = ctx .Repo .Commit .GetCommitByPath (ctx .Repo .TreePath )
104
+ latestCommit := c .Repo .Commit
105
+ if len (c .Repo .TreePath ) > 0 {
106
+ latestCommit , err = c .Repo .Commit .GetCommitByPath (c .Repo .TreePath )
104
107
if err != nil {
105
- ctx . Handle ( 500 , "GetCommitByPath" , err )
108
+ c . ServerError ( "GetCommitByPath" , err )
106
109
return
107
110
}
108
111
}
109
- ctx .Data ["LatestCommit" ] = latestCommit
110
- ctx .Data ["LatestCommitUser" ] = models .ValidateCommitWithEmail (latestCommit )
112
+ c .Data ["LatestCommit" ] = latestCommit
113
+ c .Data ["LatestCommitUser" ] = models .ValidateCommitWithEmail (latestCommit )
111
114
112
- if ctx .Repo .CanEnableEditor () {
113
- ctx .Data ["CanAddFile" ] = true
114
- ctx .Data ["CanUploadFile" ] = setting .Repository .Upload .Enabled
115
+ if c .Repo .CanEnableEditor () {
116
+ c .Data ["CanAddFile" ] = true
117
+ c .Data ["CanUploadFile" ] = setting .Repository .Upload .Enabled
115
118
}
116
119
}
117
120
@@ -157,7 +160,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
157
160
ctx .Data ["IsMarkdown" ] = isMarkdown
158
161
ctx .Data ["ReadmeExist" ] = isMarkdown && markup .IsReadmeFile (blob .Name ())
159
162
160
- ctx .Data ["IsIPythonNotebook" ] = strings . HasSuffix (blob .Name (), ".ipynb" )
163
+ ctx .Data ["IsIPythonNotebook" ] = markup . IsIPythonNotebook (blob .Name ())
161
164
162
165
if isMarkdown {
163
166
ctx .Data ["FileContent" ] = string (markup .Markdown (buf , path .Dir (treeLink ), ctx .Repo .Repository .ComposeMetas ()))
0 commit comments