| 1 | {{define "wiki" }}<section id="wiki-list" > |
| 2 | <h1>Wiki</h1> |
| 3 | <form method="get" action="/wiki" id="wiki-search" ><label>Search <input name="q" value="{{.Query.Get " q"}}" placeholder="title or summary" autocomplete="off" ></label> <button>Search</button>{{if .Query.Get "q" }} <a href="/wiki" >clear</a>{{end}}</form> |
| 4 | {{if and .Actor (.Query.Get "new" )}}<h2>New page</h2>{{template "wikiEditor" .}} |
| 5 | {{end}}{{if .Error}}{{template "alert" .Error}} |
| 6 | {{else if .Feed}}{{$can := index (asMap .Event) "can_approve" }}<table id="rows" > |
| 7 | <thead><tr><th>page</th><th>author</th><th>versions</th><th>merge requests</th><th>updated</th></tr></thead> |
| 8 | <tbody> |
| 9 | {{range .Feed}}{{$p := asMap .}}{{$v := asMap (index $p "version" )}}{{$s := wikiProposal $v $.Actor $can}}<tr{{if $s.Shown}} data-state="{{$s.State}}" {{end}}><td><a href="{{wikiURL (str (index $p " d"))}}" >{{str (index $p "title" )}}</a>{{if $s.Shown}} <small>proposed | {{$s.State}}</small>{{end}}</td><td>{{template "nostrName" (str (index $v "author" ))}}</td><td>{{str (index $p "versions" )}}</td><td>{{str (index $p "open_merges" )}} open</td><td>{{when (index $v "created_at" )}}</td></tr> |
| 10 | {{end}}</tbody> |
| 11 | </table> |
| 12 | {{else}}<p>No pages yet.</p> |
| 13 | {{end}}{{with (asMap .Event).next_cursor}}<p id="pages" ><a href="{{browsePageURL " /wiki" $.Query " cursor" .}}" >next page</a></p> |
| 14 | {{end}}</section> |
| 15 | {{end}} |
| 16 | |
| 17 | {{define "wikipage" }}{{$d := .Query.Get "d" }}{{if .Error}}<section id="wiki-page" > |
| 18 | <h1>{{$d}}</h1> |
| 19 | {{if hasPrefix .Error "not found:" }}<p>There is no page named <code>{{$d}}</code> yet.</p> |
| 20 | {{if .Actor}}{{template "wikiEditor" .}}{{else}}<p><a href="{{signinURL .Base .Path .Query}}" >Sign in</a> to write it.</p>{{end}} |
| 21 | {{else}}{{template "alert" .Error}}{{end}}</section> |
| 22 | {{else}}{{$w := wikiView .Event}}<section id="wiki-page" > |
| 23 | <h1>{{$w.Title}}</h1> |
| 24 | {{template "alert" .Notice}}{{if not $w.Version}}<p>This name has no article of its own.</p> |
| 25 | {{template "wikiRedirects" $w}}{{if .Actor}}{{template "wikiEditor" .}}{{end}} |
| 26 | {{else}}{{$s := wikiProposal $w.Version $.Actor $w.CanApprove}}{{if $s.Shown}}<wiki-proposal data-state="{{$s.State}}" >Proposed by {{template "nostrName" $w.Author}} | {{$s.State}}{{if $s.By}} {{when $s.At}} by {{template "nostrName" $s.By}}{{end}}{{if $s.Decide}}<nostr-react event="{{str (index $w.Version " id")}}" pubkey="{{$w.Author}}" kind="30818" ><button name="reaction" value="+" >Accept</button><button name="reaction" value="-" >Reject</button></nostr-react>{{end}}{{if $w.ReadersRevision}}<small>showing {{$s.State}} revision {{$w.Revision}}; readers see approved revision {{$w.ReadersRevision}}</small>{{end}}</wiki-proposal> |
| 27 | {{end}}{{range $m := $w.OpenMerges}}<merge-request>{{template "nostrName" (str (index $m "author" ))}} proposes a new version of this page | <a href="{{wikiURL $w.D " merge" (str (index $m " id"))}}" >compare</a>{{if eq $.Actor (str (index $m "destination" ))}}<nostr-react event="{{str (index $m " id")}}" pubkey="{{str (index $m " author")}}" kind="818" ><button name="reaction" value="+" >Accept</button><button name="reaction" value="-" >Reject</button></nostr-react>{{end}}<a href="/e/{{str (index $m " id")}}" >Reply</a></merge-request> |
| 28 | {{end}}{{if .Query.Get "merge" }}{{template "wikiCompare" .}} |
| 29 | {{else if .Query.Get "edit" }}{{template "wikiEditor" .}} |
| 30 | {{else if .Query.Get "history" }}{{template "wikiHistory" .}} |
| 31 | {{else}}<wiki-article><header>wiki | {{$w.D}} | revision {{$w.Revision}} by {{template "nostrName" $w.Author}} | version {{$w.Number}} of {{$w.Count}} | {{$w.Forks}} fork{{if ne $w.Forks 1}}s{{end}}</header> |
| 32 | {{if $w.Archived}}<p id="wiki-revision-note" >revision {{$w.Revision}} of {{$w.Revisions}} by this author; a newer revision exists | <a href="{{wikiURL $w.D " author" $w.Author}}" >show the newest</a></p> |
| 33 | {{end}}{{with asMap (index $w.Version "fork" )}}<p><small>forked from <a href="{{wikiURL $w.D " version" (str (index . " e"))}}" >{{shortID (index . "e" )}}</a></small></p> |
| 34 | {{end}}{{with asMap (index $w.Version "defer" )}}<p><small>the author defers to <a href="{{wikiURL $w.D " version" (str (index . " e"))}}" >{{shortID (index . "e" )}}</a></small></p> |
| 35 | {{end}}{{wikiHTML (index $w.Version "content" )}}</wiki-article> |
| 36 | {{template "wikiRedirects" $w}}{{end}}{{end}}</section> |
| 37 | {{end}}{{end}} |
| 38 | |
| 39 | {{/* wikiRedirects lists the articles a name leads to. */}} |
| 40 | {{define "wikiRedirects" }}{{if .RedirectsFrom}}<p id="wiki-redirects" >This name leads to {{range $i, $r := .RedirectsFrom}}{{if $i}}, {{end}}<a href="{{wikiURL (str (index $r " target_d"))}}" >{{str (index $r "target_d" )}}</a>{{end}}.</p> |
| 41 | {{end}}{{end}} |
| 42 | |
| 43 | {{/* wikiEditor publishes a version of the page in view, or a new page. */}} |
| 44 | {{define "wikiEditor" }}{{$w := wikiView .Event}}{{$d := or $w.D (.Query.Get "d" )}}<wiki-compose name="{{$d}}" author="{{$w.Author}}" coordinate="{{str (index $w.Version " coordinate")}}" event="{{str (index $w.Version " id")}}" > |
| 45 | <label>Title <input name="title" value="{{$w.Title}}" required autocomplete="off" ></label> |
| 46 | <label>Name <input name="name" value="{{$d}}" required autocomplete="off" spellcheck="false" ></label> |
| 47 | <label>Summary <input name="summary" value="{{str (index $w.Version " summary")}}" autocomplete="off" ></label> |
| 48 | <label>Content <textarea name="content" rows="16" placeholder="Djot markup: # heading, *emphasis*, [[Page Name]]" >{{str (index $w.Version "content" )}}</textarea></label> |
| 49 | <button name="action" value="publish" >Publish</button>{{if and $w.Author (ne $w.Author .Actor)}} <button name="action" value="propose" >Propose to {{shortID $w.Author}}</button>{{end}} |
| 50 | </wiki-compose><noscript><p>JavaScript and a connected signer are required to publish.</p></noscript>{{end}} |
| 51 | |
| 52 | {{/* wikiCompare shows the proposed version of a merge request above the current one. */}} |
| 53 | {{define "wikiCompare" }}{{$w := wikiView .Event}}{{$m := asMap .Merge}}{{if not $m}}<p>The merge request could not be loaded.</p> |
| 54 | {{else}}{{$r := asMap (index $m "merge" )}}<div id="wiki-compare" > |
| 55 | <p id="merge-status" >merge request <a href="/e/{{str (index $r " id")}}" >{{shortID (index $r "id" )}}</a> | from {{template "nostrName" (str (index $r "author" ))}} to {{template "nostrName" (str (index $r "destination" ))}} | {{str (index $r "status" )}}{{with index $r "content" }} | {{.}}{{end}}</p> |
| 56 | {{with asMap (index $m "proposed" )}}<h2>Proposed version</h2> |
| 57 | <wiki-article><header>wiki | {{str (index . "d" )}} | by {{template "nostrName" (str (index . "author" ))}} | {{when (index . "created_at" )}}</header> |
| 58 | {{wikiHTML (index . "content" )}}</wiki-article> |
| 59 | {{else}}<p>The proposed version is not available.</p> |
| 60 | {{end}}{{with asMap (index $m "target" )}}<h2>Current version</h2> |
| 61 | <wiki-article><header>wiki | {{str (index . "d" )}} | by {{template "nostrName" (str (index . "author" ))}} | {{when (index . "created_at" )}}</header> |
| 62 | {{wikiHTML (index . "content" )}}</wiki-article> |
| 63 | {{else}}<p>The destination author has no version of this page.</p> |
| 64 | {{end}}<p><a href="{{wikiURL $w.D}}" >back to the page</a></p></div>{{end}}{{end}} |
| 65 | |
| 66 | {{/* wikiHistory lists every revision of a page across authors, newest first. */}} |
| 67 | {{define "wikiHistory" }}{{$w := wikiView .Event}}<table id="rows" > |
| 68 | <thead><tr><th>author</th><th>revision</th><th>version</th><th>notes</th><th>published</th></tr></thead> |
| 69 | <tbody> |
| 70 | {{range $w.History}}{{$s := wikiProposal . $.Actor $w.CanApprove}}<tr{{if $s.Shown}} data-state="{{$s.State}}" {{end}}><td>{{template "nostrName" (str (index . "author" ))}}</td><td>{{str (index . "revision" )}} <small>{{if index . "superseded_by" }}replaced{{else}}current{{end}}</small></td><td><a href="{{wikiURL $w.D " version" (str (index . " id"))}}" >{{shortID (index . "id" )}}</a></td><td>{{with asMap (index . "fork" )}}fork of {{shortID (index . "e" )}}{{end}}{{with asMap (index . "defer" )}} defers to {{shortID (index . "e" )}}{{end}}{{with index . "likes" }} | {{str .}} likes{{end}}{{if $s.Shown}} | proposed {{$s.State}}{{end}}</td><td>{{when (index . "created_at" )}}</td></tr> |
| 71 | {{end}}</tbody> |
| 72 | </table> |
| 73 | <p><a href="{{wikiURL $w.D}}" >back to the page</a></p>{{end}} |
| 74 | |
| 75 | {{define "panel-wiki" }}{{if eq .Tab "wiki" }}<section><h4>Wiki</h4><table><tr><th>protocol</th><td>NIP-54</td></tr><tr><th>markup</th><td>Djot</td></tr><tr><th>reads</th><td>{{.Policy.Reads}}</td></tr></table></section> |
| 76 | <section><h4>Actions</h4><ul>{{if .Actor}}<li><a href="/wiki?new=1" >new page</a></li>{{else}}<li><a href="{{signinURL .Base .Path .Query}}" >sign in to write</a></li>{{end}}</ul></section> |
| 77 | {{else}}{{$w := wikiView .Event}}<section><h4>Page</h4><table><tr><th>name</th><td><code>{{or $w.D (.Query.Get "d" )}}</code></td></tr><tr><th>versions</th><td>{{$w.Count}}</td></tr>{{if $w.History}}<tr><th>revisions</th><td>{{len $w.History}}</td></tr>{{end}}<tr><th>merge requests</th><td>{{$w.OpenCount}} open</td></tr><tr><th>links</th><td>{{$w.Links}}</td></tr></table></section> |
| 78 | {{if $w.Others}}<section><h4>Other versions</h4><ul>{{range $w.Others}}{{$s := wikiProposal . $.Actor $w.CanApprove}}<li{{if $s.Shown}} data-state="{{$s.State}}" {{end}}><a href="{{wikiURL $w.D " version" (str (index . " id"))}}" >{{shortID (index . "author" )}}</a>{{with asMap (index . "fork" )}} | fork{{end}}{{if $s.Shown}} | proposed {{$s.State}}{{end}} <small>{{short (index . "created_at" )}}</small></li>{{end}}</ul></section> |
| 79 | {{end}}{{if $w.RedirectsTo}}<section><h4>Also known as</h4><ul>{{range $w.RedirectsTo}}<li><code>{{str (index . "d" )}}</code></li>{{end}}</ul></section> |
| 80 | {{end}}<section><h4>Actions</h4><ul>{{if $w.Version}}{{if eq .Actor $w.Author}}<li><a href="{{wikiURL $w.D " edit" " 1"}}" >edit</a></li>{{else if .Actor}}<li><a href="{{wikiURL $w.D " edit" " 1"}}" >fork</a></li>{{end}}<li><a href="{{wikiURL $w.D " history" " 1"}}" >history</a></li>{{end}}{{if .Actor}}<li><a href="/wiki?new=1" >new page</a></li>{{else}}<li><a href="{{signinURL .Base .Path .Query}}" >sign in to write</a></li>{{end}}</ul></section>{{end}}{{end}} |