diff --git a/hyphae/iterators.go b/hyphae/iterators.go index 4c06216..9fb494e 100644 --- a/hyphae/iterators.go +++ b/hyphae/iterators.go @@ -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] } } diff --git a/views/readers.qtpl b/views/readers.qtpl index 3b597f6..c07ebd3 100644 --- a/views/readers.qtpl +++ b/views/readers.qtpl @@ -125,7 +125,7 @@ If you rename .prevnext, change the docs too.
-

Please note that viewing attachments of hyphae is not supported in history for now.

+

Please note that viewing attachments of hyphae is not supported in history for now. Get Mycomarkup source of this revision

{%s= NaviTitleHTML(h) %} {%s= contents %}
diff --git a/views/readers.qtpl.go b/views/readers.qtpl.go index 02a66b7..56b4ef6 100644 --- a/views/readers.qtpl.go +++ b/views/readers.qtpl.go @@ -398,7 +398,15 @@ func StreamRevisionHTML(qw422016 *qt422016.Writer, rq *http.Request, h *hyphae.H
-

Please note that viewing attachments of hyphae is not supported in history for now.

+

Please note that viewing attachments of hyphae is not supported in history for now. Get Mycomarkup source of this revision

`) //line views/readers.qtpl:129 qw422016.N().S(NaviTitleHTML(h)) diff --git a/web/readers.go b/web/readers.go index 8c0289d..f2d0efe 100644 --- a/web/readers.go +++ b/web/readers.go @@ -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// +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 (