|
|
@ -10,6 +10,7 @@ import (
|
|
10
|
10
|
"time"
|
|
11
|
11
|
|
|
12
|
12
|
"github.com/libgit2/git2go"
|
|
|
13
|
"github.com/russross/blackfriday"
|
|
13
|
14
|
)
|
|
14
|
15
|
|
|
15
|
16
|
func main() {
|
|
|
@ -174,7 +175,7 @@ func (fc *FancyFile) Type() string {
|
|
174
|
175
|
return strings.ToLower(fc.entry.Type.String())
|
|
175
|
176
|
}
|
|
176
|
177
|
|
|
177
|
|
func (fc *FancyFile) Contents() (string, error) {
|
|
|
178
|
func (fc *FancyFile) RawContents() (string, error) {
|
|
178
|
179
|
blob, err := fc.repo.LookupBlob(fc.entry.Id)
|
|
179
|
180
|
if err != nil {
|
|
180
|
181
|
return "", err
|
|
|
@ -183,6 +184,25 @@ func (fc *FancyFile) Contents() (string, error) {
|
|
183
|
184
|
return string(blob.Contents()), nil
|
|
184
|
185
|
}
|
|
185
|
186
|
|
|
|
187
|
func (fc *FancyFile) Contents() (template.HTML, error) {
|
|
|
188
|
blob, err := fc.repo.LookupBlob(fc.entry.Id)
|
|
|
189
|
if err != nil {
|
|
|
190
|
return "", err
|
|
|
191
|
}
|
|
|
192
|
|
|
|
193
|
buf := new(bytes.Buffer)
|
|
|
194
|
contents := blob.Contents()
|
|
|
195
|
if strings.HasSuffix(fc.entry.Name, ".md") {
|
|
|
196
|
buf.Write(blackfriday.MarkdownCommon(contents))
|
|
|
197
|
} else {
|
|
|
198
|
buf.WriteString("<code><pre>")
|
|
|
199
|
template.HTMLEscape(buf, contents)
|
|
|
200
|
buf.WriteString("</pre></code>")
|
|
|
201
|
}
|
|
|
202
|
|
|
|
203
|
return template.HTML(buf.String()), nil
|
|
|
204
|
}
|
|
|
205
|
|
|
186
|
206
|
var repoTmpl = template.Must(template.New("").Parse(`<!doctype html>
|
|
187
|
207
|
<html>
|
|
188
|
208
|
<head>
|
|
|
@ -210,9 +230,9 @@ var repoTmpl = template.Must(template.New("").Parse(`<!doctype html>
|
|
210
|
230
|
{{ if .Repo.Commit.Readme }}
|
|
211
|
231
|
<section id="file" class="readme">
|
|
212
|
232
|
<h1>{{ .Repo.Commit.Readme.Name }}</h1>
|
|
213
|
|
<code>
|
|
214
|
|
<pre>{{ .Repo.Commit.Readme.Contents }}</pre>
|
|
215
|
|
</code>
|
|
|
233
|
<div class="contents">
|
|
|
234
|
{{ .Repo.Commit.Readme.Contents }}
|
|
|
235
|
</div>
|
|
216
|
236
|
</section>
|
|
217
|
237
|
{{ end }}
|
|
218
|
238
|
</body>
|