{{ .HTMLReadme }}
+ {{ else }}
+ {{ .HTMLReadme }}
+ {{ end }}
diff --git a/appview/pages/pages.go b/appview/pages/pages.go index eb19450..772f08d 100644 --- a/appview/pages/pages.go +++ b/appview/pages/pages.go @@ -17,6 +17,7 @@ import ( 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" @@ -198,6 +199,8 @@ type RepoIndexParams struct { Active string TagMap map[string][]string types.RepoIndexResponse + HTMLReadme template.HTML + Raw bool } func (p *Pages) RepoIndexPage(w io.Writer, params RepoIndexParams) error { @@ -205,6 +208,20 @@ 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) } diff --git a/appview/pages/templates/repo/index.html b/appview/pages/templates/repo/index.html index b977f33..f3d3145 100644 --- a/appview/pages/templates/repo/index.html +++ b/appview/pages/templates/repo/index.html @@ -114,7 +114,7 @@ {{ end }} -{{ define "commitLog" }} +{{ define "commitLog" }}
{{ .HTMLReadme }}
+ {{ else }}
+ {{ .HTMLReadme }}
+ {{ end }}
%s`, 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) @@ -147,15 +128,16 @@ func (h *Handle) RepoIndex(w http.ResponseWriter, r *http.Request) { } 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) diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..d32a190 --- /dev/null +++ b/readme.md @@ -0,0 +1,2 @@ +# tangled +> git collaboration platform built on atproto diff --git a/types/repo.go b/types/repo.go index fe6358a..01d0f73 100644 --- a/types/repo.go +++ b/types/repo.go @@ -1,21 +1,20 @@ 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 {