forked from tangled.org/core
this repo has no description

clean up readmes

anirudh.fi 0e8f3837 ede0c38f

verified
Changed files
+53 -49
appview
pages
templates
repo
knotserver
types
+17
appview/pages/pages.go
···
chromahtml "github.com/alecthomas/chroma/v2/formatters/html"
"github.com/alecthomas/chroma/v2/lexers"
"github.com/alecthomas/chroma/v2/styles"
+
"github.com/microcosm-cc/bluemonday"
"github.com/sotangled/tangled/appview/auth"
"github.com/sotangled/tangled/appview/db"
"github.com/sotangled/tangled/types"
···
Active string
TagMap map[string][]string
types.RepoIndexResponse
+
HTMLReadme template.HTML
+
Raw bool
}
func (p *Pages) RepoIndexPage(w io.Writer, params RepoIndexParams) error {
···
if params.IsEmpty {
return p.executeRepo("repo/empty", w, params)
}
+
+
if params.ReadmeFileName != "" {
+
var htmlString string
+
ext := filepath.Ext(params.ReadmeFileName)
+
switch ext {
+
case ".md", ".markdown", ".mdown", ".mkdn", ".mkd":
+
htmlString = renderMarkdown(params.Readme)
+
default:
+
htmlString = string(params.Readme)
+
params.Raw = true
+
}
+
params.HTMLReadme = template.HTML(bluemonday.NewPolicy().Sanitize(htmlString))
+
}
+
return p.executeRepo("repo/index", w, params)
}
+9 -5
appview/pages/templates/repo/index.html
···
{{ end }}
-
{{ define "commitLog" }}
+
{{ define "commitLog" }}
<div id="commit-log" class="hidden md:block md:col-span-1">
{{ range .Commits }}
<div class="relative px-2 pb-8">
···
{{ define "repoAfter" }}
-
{{- if .Readme }}
-
<section class="mt-4 p-6 rounded bg-white w-full mx-auto overflow-auto prose">
-
<article class="readme">
-
{{- .Readme -}}
+
{{- if .HTMLReadme }}
+
<section class="mt-4 p-6 rounded bg-white w-full mx-auto overflow-auto {{ if not .Raw }} prose {{ end }}">
+
<article class="{{ if .Raw }}whitespace-pre{{end}}">
+
{{ if .Raw }}
+
<pre>{{ .HTMLReadme }}</pre>
+
{{ else }}
+
{{ .HTMLReadme }}
+
{{ end }}
</article>
</section>
{{- end -}}
+1 -1
appview/pages/templates/repo/issues/new.html
···
id="body"
rows="6"
class="w-full resize-y"
-
placeholder="Describe your issue."
+
placeholder="Describe your issue. Markdown is supported."
></textarea>
</div>
<div>
+14 -32
knotserver/routes.go
···
"encoding/json"
"errors"
"fmt"
-
"html/template"
"log"
"net/http"
"path/filepath"
···
gogit "github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/object"
-
"github.com/russross/blackfriday/v2"
"github.com/sotangled/tangled/knotserver/db"
"github.com/sotangled/tangled/knotserver/git"
"github.com/sotangled/tangled/types"
···
rtags = append(rtags, &tr)
}
-
var readmeContent template.HTML
+
var readmeContent string
+
var readmeFile string
for _, readme := range h.c.Repo.Readme {
-
ext := filepath.Ext(readme)
content, _ := gr.FileContent(readme)
if len(content) > 0 {
-
switch ext {
-
case ".md", ".mkd", ".markdown":
-
unsafe := blackfriday.Run(
-
[]byte(content),
-
blackfriday.WithExtensions(blackfriday.CommonExtensions),
-
)
-
html := sanitize(unsafe)
-
readmeContent = template.HTML(html)
-
default:
-
safe := sanitize([]byte(content))
-
readmeContent = template.HTML(
-
fmt.Sprintf(`<pre>%s</pre>`, safe),
-
)
-
}
-
break
+
readmeContent = string(content)
+
readmeFile = readme
}
}
-
if readmeContent == "" {
-
l.Warn("no readme found")
-
}
-
files, err := gr.FileTree("")
if err != nil {
writeError(w, err.Error(), http.StatusInternalServerError)
···
}
resp := types.RepoIndexResponse{
-
IsEmpty: false,
-
Ref: ref,
-
Commits: commits,
-
Description: getDescription(path),
-
Readme: readmeContent,
-
Files: files,
-
Branches: bs,
-
Tags: rtags,
-
TotalCommits: total,
+
IsEmpty: false,
+
Ref: ref,
+
Commits: commits,
+
Description: getDescription(path),
+
Readme: readmeContent,
+
ReadmeFileName: readmeFile,
+
Files: files,
+
Branches: bs,
+
Tags: rtags,
+
TotalCommits: total,
}
writeJSON(w, resp)
+2
readme.md
···
+
# tangled
+
> git collaboration platform built on atproto
+10 -11
types/repo.go
···
package types
import (
-
"html/template"
-
"github.com/go-git/go-git/v5/plumbing/object"
)
type RepoIndexResponse struct {
-
IsEmpty bool `json:"is_empty"`
-
Ref string `json:"ref,omitempty"`
-
Readme template.HTML `json:"readme,omitempty"`
-
Commits []*object.Commit `json:"commits,omitempty"`
-
Description string `json:"description,omitempty"`
-
Files []NiceTree `json:"files,omitempty"`
-
Branches []Branch `json:"branches,omitempty"`
-
Tags []*TagReference `json:"tags,omitempty"`
-
TotalCommits int `json:"total_commits,omitempty"`
+
IsEmpty bool `json:"is_empty"`
+
Ref string `json:"ref,omitempty"`
+
Readme string `json:"readme,omitempty"`
+
ReadmeFileName string `json:"readme_file_name,omitempty"`
+
Commits []*object.Commit `json:"commits,omitempty"`
+
Description string `json:"description,omitempty"`
+
Files []NiceTree `json:"files,omitempty"`
+
Branches []Branch `json:"branches,omitempty"`
+
Tags []*TagReference `json:"tags,omitempty"`
+
TotalCommits int `json:"total_commits,omitempty"`
}
type RepoLogResponse struct {