appview/pages: show README files in tree listings #582

We have README files displayed on the main page of a repository, but we don't do that on subfolders.

In the previous commit, we returned these from the knotserver in the RepoTreeResponse. We now need to do something similar to what we do on the index page on the individual tree pages...

Signed-off-by: Skyler Grey minion@freshlybakedca.ke

Changed files
+43
appview
pages
templates
repo
+16
appview/pages/pages.go
···
Active string
BreadCrumbs [][]string
TreePath string
+
HTMLReadme template.HTML
+
Raw bool
types.RepoTreeResponse
}
···
func (p *Pages) RepoTree(w io.Writer, params RepoTreeParams) error {
params.Active = "overview"
+
+
if params.ReadmeFileName != "" {
+
ext := filepath.Ext(params.ReadmeFileName)
+
switch ext {
+
case ".md", ".markdown", ".mdown", ".mkdn", ".mkd":
+
params.Raw = false
+
htmlString := p.rctx.RenderMarkdown(params.Readme)
+
sanitized := p.rctx.SanitizeDefault(htmlString)
+
params.HTMLReadme = template.HTML(sanitized)
+
default:
+
params.Raw = true
+
}
+
}
+
return p.executeRepo("repo/tree", w, params)
}
+27
appview/pages/templates/repo/tree.html
···
</div>
</main>
{{end}}
+
+
{{ define "repoAfter" }}
+
{{- if or .HTMLReadme .Readme -}}
+
<div class="mt-4 rounded bg-white dark:bg-gray-800 drop-shadow-sm w-full mx-auto overflow-hidden">
+
{{- if .ReadmeFileName -}}
+
<div class="px-4 py-2 bg-gray-50 dark:bg-gray-700 border-b border-gray-200 dark:border-gray-600 flex items-center gap-2">
+
{{ i "file-text" "w-4 h-4" "text-gray-600 dark:text-gray-400" }}
+
<span class="font-mono text-sm text-gray-800 dark:text-gray-200">{{ .ReadmeFileName }}</span>
+
</div>
+
{{- end -}}
+
<section
+
class="p-6 overflow-auto {{ if not .Raw }}
+
prose dark:prose-invert dark:[&_pre]:bg-gray-900
+
dark:[&_code]:text-gray-300 dark:[&_pre_code]:bg-gray-900
+
dark:[&_pre]:border dark:[&_pre]:border-gray-700
+
{{ end }}"
+
>
+
<article class="{{ if .Raw }}whitespace-pre{{ end }}">{{- if .Raw -}}<pre class="dark:bg-gray-800 dark:text-white overflow-x-auto">
+
{{- .Readme -}}
+
</pre>
+
{{- else -}}
+
{{ .HTMLReadme }}
+
{{- end -}}</article>
+
</section>
+
</div>
+
{{- end -}}
+
{{ end }}