tangled
alpha
login
or
join now
moll.dev
/
core
forked from
tangled.org/core
this repo has no description
0
fork
atom
overview
issues
pulls
pipelines
clean up readmes
anirudh.fi
11 months ago
9e6276dd
6bed8aa8
+53
-49
6 changed files
expand all
collapse all
unified
split
appview
pages
pages.go
templates
repo
index.html
issues
new.html
knotserver
routes.go
readme.md
types
repo.go
+17
appview/pages/pages.go
···
17
17
chromahtml "github.com/alecthomas/chroma/v2/formatters/html"
18
18
"github.com/alecthomas/chroma/v2/lexers"
19
19
"github.com/alecthomas/chroma/v2/styles"
20
20
+
"github.com/microcosm-cc/bluemonday"
20
21
"github.com/sotangled/tangled/appview/auth"
21
22
"github.com/sotangled/tangled/appview/db"
22
23
"github.com/sotangled/tangled/types"
···
198
199
Active string
199
200
TagMap map[string][]string
200
201
types.RepoIndexResponse
202
202
+
HTMLReadme template.HTML
203
203
+
Raw bool
201
204
}
202
205
203
206
func (p *Pages) RepoIndexPage(w io.Writer, params RepoIndexParams) error {
···
205
208
if params.IsEmpty {
206
209
return p.executeRepo("repo/empty", w, params)
207
210
}
211
211
+
212
212
+
if params.ReadmeFileName != "" {
213
213
+
var htmlString string
214
214
+
ext := filepath.Ext(params.ReadmeFileName)
215
215
+
switch ext {
216
216
+
case ".md", ".markdown", ".mdown", ".mkdn", ".mkd":
217
217
+
htmlString = renderMarkdown(params.Readme)
218
218
+
default:
219
219
+
htmlString = string(params.Readme)
220
220
+
params.Raw = true
221
221
+
}
222
222
+
params.HTMLReadme = template.HTML(bluemonday.NewPolicy().Sanitize(htmlString))
223
223
+
}
224
224
+
208
225
return p.executeRepo("repo/index", w, params)
209
226
}
210
227
+9
-5
appview/pages/templates/repo/index.html
···
114
114
{{ end }}
115
115
116
116
117
117
-
{{ define "commitLog" }}
117
117
+
{{ define "commitLog" }}
118
118
<div id="commit-log" class="hidden md:block md:col-span-1">
119
119
{{ range .Commits }}
120
120
<div class="relative px-2 pb-8">
···
191
191
192
192
193
193
{{ define "repoAfter" }}
194
194
-
{{- if .Readme }}
195
195
-
<section class="mt-4 p-6 rounded bg-white w-full mx-auto overflow-auto prose">
196
196
-
<article class="readme">
197
197
-
{{- .Readme -}}
194
194
+
{{- if .HTMLReadme }}
195
195
+
<section class="mt-4 p-6 rounded bg-white w-full mx-auto overflow-auto {{ if not .Raw }} prose {{ end }}">
196
196
+
<article class="{{ if .Raw }}whitespace-pre{{end}}">
197
197
+
{{ if .Raw }}
198
198
+
<pre>{{ .HTMLReadme }}</pre>
199
199
+
{{ else }}
200
200
+
{{ .HTMLReadme }}
201
201
+
{{ end }}
198
202
</article>
199
203
</section>
200
204
{{- end -}}
+1
-1
appview/pages/templates/repo/issues/new.html
···
18
18
id="body"
19
19
rows="6"
20
20
class="w-full resize-y"
21
21
-
placeholder="Describe your issue."
21
21
+
placeholder="Describe your issue. Markdown is supported."
22
22
></textarea>
23
23
</div>
24
24
<div>
+14
-32
knotserver/routes.go
···
8
8
"encoding/json"
9
9
"errors"
10
10
"fmt"
11
11
-
"html/template"
12
11
"log"
13
12
"net/http"
14
13
"path/filepath"
···
21
20
gogit "github.com/go-git/go-git/v5"
22
21
"github.com/go-git/go-git/v5/plumbing"
23
22
"github.com/go-git/go-git/v5/plumbing/object"
24
24
-
"github.com/russross/blackfriday/v2"
25
23
"github.com/sotangled/tangled/knotserver/db"
26
24
"github.com/sotangled/tangled/knotserver/git"
27
25
"github.com/sotangled/tangled/types"
···
102
100
rtags = append(rtags, &tr)
103
101
}
104
102
105
105
-
var readmeContent template.HTML
103
103
+
var readmeContent string
104
104
+
var readmeFile string
106
105
for _, readme := range h.c.Repo.Readme {
107
107
-
ext := filepath.Ext(readme)
108
106
content, _ := gr.FileContent(readme)
109
107
if len(content) > 0 {
110
110
-
switch ext {
111
111
-
case ".md", ".mkd", ".markdown":
112
112
-
unsafe := blackfriday.Run(
113
113
-
[]byte(content),
114
114
-
blackfriday.WithExtensions(blackfriday.CommonExtensions),
115
115
-
)
116
116
-
html := sanitize(unsafe)
117
117
-
readmeContent = template.HTML(html)
118
118
-
default:
119
119
-
safe := sanitize([]byte(content))
120
120
-
readmeContent = template.HTML(
121
121
-
fmt.Sprintf(`<pre>%s</pre>`, safe),
122
122
-
)
123
123
-
}
124
124
-
break
108
108
+
readmeContent = string(content)
109
109
+
readmeFile = readme
125
110
}
126
111
}
127
112
128
128
-
if readmeContent == "" {
129
129
-
l.Warn("no readme found")
130
130
-
}
131
131
-
132
113
files, err := gr.FileTree("")
133
114
if err != nil {
134
115
writeError(w, err.Error(), http.StatusInternalServerError)
···
147
128
}
148
129
149
130
resp := types.RepoIndexResponse{
150
150
-
IsEmpty: false,
151
151
-
Ref: ref,
152
152
-
Commits: commits,
153
153
-
Description: getDescription(path),
154
154
-
Readme: readmeContent,
155
155
-
Files: files,
156
156
-
Branches: bs,
157
157
-
Tags: rtags,
158
158
-
TotalCommits: total,
131
131
+
IsEmpty: false,
132
132
+
Ref: ref,
133
133
+
Commits: commits,
134
134
+
Description: getDescription(path),
135
135
+
Readme: readmeContent,
136
136
+
ReadmeFileName: readmeFile,
137
137
+
Files: files,
138
138
+
Branches: bs,
139
139
+
Tags: rtags,
140
140
+
TotalCommits: total,
159
141
}
160
142
161
143
writeJSON(w, resp)
+2
readme.md
···
1
1
+
# tangled
2
2
+
> git collaboration platform built on atproto
+10
-11
types/repo.go
···
1
1
package types
2
2
3
3
import (
4
4
-
"html/template"
5
5
-
6
4
"github.com/go-git/go-git/v5/plumbing/object"
7
5
)
8
6
9
7
type RepoIndexResponse struct {
10
10
-
IsEmpty bool `json:"is_empty"`
11
11
-
Ref string `json:"ref,omitempty"`
12
12
-
Readme template.HTML `json:"readme,omitempty"`
13
13
-
Commits []*object.Commit `json:"commits,omitempty"`
14
14
-
Description string `json:"description,omitempty"`
15
15
-
Files []NiceTree `json:"files,omitempty"`
16
16
-
Branches []Branch `json:"branches,omitempty"`
17
17
-
Tags []*TagReference `json:"tags,omitempty"`
18
18
-
TotalCommits int `json:"total_commits,omitempty"`
8
8
+
IsEmpty bool `json:"is_empty"`
9
9
+
Ref string `json:"ref,omitempty"`
10
10
+
Readme string `json:"readme,omitempty"`
11
11
+
ReadmeFileName string `json:"readme_file_name,omitempty"`
12
12
+
Commits []*object.Commit `json:"commits,omitempty"`
13
13
+
Description string `json:"description,omitempty"`
14
14
+
Files []NiceTree `json:"files,omitempty"`
15
15
+
Branches []Branch `json:"branches,omitempty"`
16
16
+
Tags []*TagReference `json:"tags,omitempty"`
17
17
+
TotalCommits int `json:"total_commits,omitempty"`
19
18
}
20
19
21
20
type RepoLogResponse struct {