forked from tangled.org/core
A fork of tangled.org/core to hack on

appview/pages: show README files in tree listings

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>

a.starrysky.fyi 5bfea67a 538923ff

verified
Changed files
+43
appview
pages
templates
repo
+16
appview/pages/pages.go
··· 686 686 Active string 687 687 BreadCrumbs [][]string 688 688 TreePath string 689 + HTMLReadme template.HTML 690 + Raw bool 689 691 types.RepoTreeResponse 690 692 } 691 693 ··· 712 714 713 715 func (p *Pages) RepoTree(w io.Writer, params RepoTreeParams) error { 714 716 params.Active = "overview" 717 + 718 + if params.ReadmeFileName != "" { 719 + ext := filepath.Ext(params.ReadmeFileName) 720 + switch ext { 721 + case ".md", ".markdown", ".mdown", ".mkdn", ".mkd": 722 + params.Raw = false 723 + htmlString := p.rctx.RenderMarkdown(params.Readme) 724 + sanitized := p.rctx.SanitizeDefault(htmlString) 725 + params.HTMLReadme = template.HTML(sanitized) 726 + default: 727 + params.Raw = true 728 + } 729 + } 730 + 715 731 return p.executeRepo("repo/tree", w, params) 716 732 } 717 733
+27
appview/pages/templates/repo/tree.html
··· 88 88 </div> 89 89 </main> 90 90 {{end}} 91 + 92 + {{ define "repoAfter" }} 93 + {{- if or .HTMLReadme .Readme -}} 94 + <div class="mt-4 rounded bg-white dark:bg-gray-800 drop-shadow-sm w-full mx-auto overflow-hidden"> 95 + {{- if .ReadmeFileName -}} 96 + <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"> 97 + {{ i "file-text" "w-4 h-4" "text-gray-600 dark:text-gray-400" }} 98 + <span class="font-mono text-sm text-gray-800 dark:text-gray-200">{{ .ReadmeFileName }}</span> 99 + </div> 100 + {{- end -}} 101 + <section 102 + class="p-6 overflow-auto {{ if not .Raw }} 103 + prose dark:prose-invert dark:[&_pre]:bg-gray-900 104 + dark:[&_code]:text-gray-300 dark:[&_pre_code]:bg-gray-900 105 + dark:[&_pre]:border dark:[&_pre]:border-gray-700 106 + {{ end }}" 107 + > 108 + <article class="{{ if .Raw }}whitespace-pre{{ end }}">{{- if .Raw -}}<pre class="dark:bg-gray-800 dark:text-white overflow-x-auto"> 109 + {{- .Readme -}} 110 + </pre> 111 + {{- else -}} 112 + {{ .HTMLReadme }} 113 + {{- end -}}</article> 114 + </section> 115 + </div> 116 + {{- end -}} 117 + {{ end }}