1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2025-01-05 17:40:26 +00:00

Add /rev-text/

This commit is contained in:
Timur Ismagilov 2021-09-23 12:36:54 +03:00
parent 71b404c4f0
commit 51704b72cd
4 changed files with 51 additions and 8 deletions

View File

@ -2,8 +2,8 @@
package hyphae
import (
"strings"
"sort"
"strings"
)
// YieldExistingHyphae iterates over all hyphae and yields all existing ones.
@ -48,14 +48,22 @@ func PathographicSort(src chan string) <-chan string {
// Classic lexicographical sort with a twist
c := 0
for {
if c == len(raw[i]) { return true }
if c == len(raw[j]) { return false }
if c == len(raw[i]) {
return true
}
if c == len(raw[j]) {
return false
}
if raw[i][c] == raw[j][c] {
c++
} else {
// The twist: subhyphae-awareness is about pushing slash upwards
if raw[i][c] == slash { return true }
if raw[j][c] == slash { return false }
if raw[i][c] == slash {
return true
}
if raw[j][c] == slash {
return false
}
return raw[i][c] < raw[j][c]
}
}

View File

@ -125,7 +125,7 @@ If you rename .prevnext, change the docs too.
<div class="layout">
<main class="main-width">
<article>
<p>Please note that viewing attachments of hyphae is not supported in history for now.</p>
<p>Please note that viewing attachments of hyphae is not supported in history for now. <a href="/rev-text/{%s revHash %}/{%s h.Name %}">Get Mycomarkup source of this revision</a></p>
{%s= NaviTitleHTML(h) %}
{%s= contents %}
</article>

View File

@ -398,7 +398,15 @@ func StreamRevisionHTML(qw422016 *qt422016.Writer, rq *http.Request, h *hyphae.H
<div class="layout">
<main class="main-width">
<article>
<p>Please note that viewing attachments of hyphae is not supported in history for now.</p>
<p>Please note that viewing attachments of hyphae is not supported in history for now. <a href="/rev-text/`)
//line views/readers.qtpl:128
qw422016.E().S(revHash)
//line views/readers.qtpl:128
qw422016.N().S(`/`)
//line views/readers.qtpl:128
qw422016.E().S(h.Name)
//line views/readers.qtpl:128
qw422016.N().S(`">Get Mycomarkup source of this revision</a></p>
`)
//line views/readers.qtpl:129
qw422016.N().S(NaviTitleHTML(h))

View File

@ -2,6 +2,7 @@ package web
import (
"fmt"
"io"
"log"
"net/http"
"os"
@ -29,6 +30,7 @@ func initReaders(r *mux.Router) {
r.PathPrefix("/text/").HandlerFunc(handlerText)
r.PathPrefix("/binary/").HandlerFunc(handlerBinary)
r.PathPrefix("/rev/").HandlerFunc(handlerRevision)
r.PathPrefix("/rev-text/").HandlerFunc(handlerRevisionText)
r.PathPrefix("/primitive-diff/").HandlerFunc(handlerPrimitiveDiff)
r.PathPrefix("/attachment/").HandlerFunc(handlerAttachment)
}
@ -64,7 +66,32 @@ func handlerPrimitiveDiff(w http.ResponseWriter, rq *http.Request) {
u))
}
// handlerRevision displays a specific revision of text part a page
// handlerRevisionText sends Mycomarkup text of the hypha at the given revision. See also: handlerRevision, handlerText.
//
// /rev-text/<revHash>/<hyphaName>
func handlerRevisionText(w http.ResponseWriter, rq *http.Request) {
util.PrepareRq(rq)
var (
shorterUrl = strings.TrimPrefix(rq.URL.Path, "/rev-text/")
firstSlashIndex = strings.IndexRune(shorterUrl, '/')
revHash = shorterUrl[:firstSlashIndex]
hyphaName = util.CanonicalName(shorterUrl[firstSlashIndex+1:])
h = hyphae.ByName(hyphaName)
textContents, err = history.FileAtRevision(h.TextPartPath(), revHash)
)
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
if err != nil {
w.WriteHeader(http.StatusNotFound)
log.Printf("While serving text of %s at revision %s: %s\n", hyphaName, revHash, err.Error())
_, _ = io.WriteString(w, "Error: "+err.Error())
return
}
log.Printf("Serving text of %s from %s at revision %s\n", hyphaName, h.TextPartPath(), revHash)
w.WriteHeader(http.StatusOK)
_, _ = io.WriteString(w, textContents)
}
// handlerRevision displays a specific revision of the text part the hypha
func handlerRevision(w http.ResponseWriter, rq *http.Request) {
util.PrepareRq(rq)
var (