diff options
author | zeripath <art27@cantab.net> | 2022-06-08 09:59:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-08 16:59:16 +0800 |
commit | ac88f21ecc5612befe51f7ab6ffcb76c681daba5 (patch) | |
tree | cbe281221d0703da0f1ecce428888e036ef311d7 /templates | |
parent | c1c07e533c9ca3be13b4af057b6b989402c12f6e (diff) | |
download | gitea-ac88f21ecc5612befe51f7ab6ffcb76c681daba5.tar.gz gitea-ac88f21ecc5612befe51f7ab6ffcb76c681daba5.zip |
Automatically render wiki TOC (#19873)
Automatically add sidebar in the wiki view containing a TOC for the wiki page.
Make the TOC collapsable
Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'templates')
-rw-r--r-- | templates/repo/wiki/view.tmpl | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/templates/repo/wiki/view.tmpl b/templates/repo/wiki/view.tmpl index 04faa90b9e..3189ed64ca 100644 --- a/templates/repo/wiki/view.tmpl +++ b/templates/repo/wiki/view.tmpl @@ -64,20 +64,39 @@ <p>{{.FormatWarning}}</p> </div> {{end}} - <div class="ui {{if .sidebarPresent}}grid equal width{{end}}" style="margin-top: 1rem;"> - <div class="ui {{if .sidebarPresent}}eleven wide column{{end}} segment markup wiki-content-main"> + <div class="ui {{if or .sidebarPresent .toc}}grid equal width{{end}}" style="margin-top: 1rem;"> + <div class="ui {{if or .sidebarPresent .toc}}eleven wide column{{end}} segment markup wiki-content-main"> {{template "repo/unicode_escape_prompt" dict "EscapeStatus" .EscapeStatus "root" $}} {{.content | Safe}} </div> - {{if .sidebarPresent}} + {{if or .sidebarPresent .toc}} <div class="column" style="padding-top: 0;"> - <div class="ui segment wiki-content-sidebar"> - {{if and .CanWriteWiki (not .Repository.IsMirror)}} - <a class="ui right floated muted" href="{{.RepoLink}}/wiki/_Sidebar?action=_edit" aria-label="{{.i18n.Tr "repo.wiki.edit_page_button"}}">{{svg "octicon-pencil"}}</a> - {{end}} - {{template "repo/unicode_escape_prompt" dict "EscapeStatus" .sidebarEscapeStatus "root" $}} - {{.sidebarContent | Safe}} - </div> + {{if .toc}} + <div class="ui segment wiki-content-toc"> + <details open> + <summary> + <div class="ui header">{{.i18n.Tr "toc"}}</div> + </summary> + {{$level := 0}} + {{range .toc}} + {{if lt $level .Level}}{{range Iterate (Subtract .Level $level)}}<ul>{{end}}{{end}} + {{if gt $level .Level}}{{range Iterate (Subtract $level .Level)}}</ul>{{end}}{{end}} + {{$level = .Level}} + <li><a href="#{{.ID}}">{{.Text}}</a></li> + {{end}} + {{range Iterate $level}}</ul>{{end}} + </details> + </div> + {{end}} + {{if .sidebarPresent}} + <div class="ui segment wiki-content-sidebar"> + {{if and .CanWriteWiki (not .Repository.IsMirror)}} + <a class="ui right floated muted" href="{{.RepoLink}}/wiki/_Sidebar?action=_edit" aria-label="{{.i18n.Tr "repo.wiki.edit_page_button"}}">{{svg "octicon-pencil"}}</a> + {{end}} + {{template "repo/unicode_escape_prompt" dict "EscapeStatus" .sidebarEscapeStatus "root" $}} + {{.sidebarContent | Safe}} + </div> + {{end}} </div> {{end}} </div> |