mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2025-01-08 10:51:09 +00:00
Add /rev-text/
This commit is contained in:
parent
71b404c4f0
commit
51704b72cd
@ -2,8 +2,8 @@
|
|||||||
package hyphae
|
package hyphae
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// YieldExistingHyphae iterates over all hyphae and yields all existing ones.
|
// 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
|
// Classic lexicographical sort with a twist
|
||||||
c := 0
|
c := 0
|
||||||
for {
|
for {
|
||||||
if c == len(raw[i]) { return true }
|
if c == len(raw[i]) {
|
||||||
if c == len(raw[j]) { return false }
|
return true
|
||||||
|
}
|
||||||
|
if c == len(raw[j]) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
if raw[i][c] == raw[j][c] {
|
if raw[i][c] == raw[j][c] {
|
||||||
c++
|
c++
|
||||||
} else {
|
} else {
|
||||||
// The twist: subhyphae-awareness is about pushing slash upwards
|
// The twist: subhyphae-awareness is about pushing slash upwards
|
||||||
if raw[i][c] == slash { return true }
|
if raw[i][c] == slash {
|
||||||
if raw[j][c] == slash { return false }
|
return true
|
||||||
|
}
|
||||||
|
if raw[j][c] == slash {
|
||||||
|
return false
|
||||||
|
}
|
||||||
return raw[i][c] < raw[j][c]
|
return raw[i][c] < raw[j][c]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -125,7 +125,7 @@ If you rename .prevnext, change the docs too.
|
|||||||
<div class="layout">
|
<div class="layout">
|
||||||
<main class="main-width">
|
<main class="main-width">
|
||||||
<article>
|
<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= NaviTitleHTML(h) %}
|
||||||
{%s= contents %}
|
{%s= contents %}
|
||||||
</article>
|
</article>
|
||||||
|
@ -398,7 +398,15 @@ func StreamRevisionHTML(qw422016 *qt422016.Writer, rq *http.Request, h *hyphae.H
|
|||||||
<div class="layout">
|
<div class="layout">
|
||||||
<main class="main-width">
|
<main class="main-width">
|
||||||
<article>
|
<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
|
//line views/readers.qtpl:129
|
||||||
qw422016.N().S(NaviTitleHTML(h))
|
qw422016.N().S(NaviTitleHTML(h))
|
||||||
|
@ -2,6 +2,7 @@ package web
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@ -29,6 +30,7 @@ func initReaders(r *mux.Router) {
|
|||||||
r.PathPrefix("/text/").HandlerFunc(handlerText)
|
r.PathPrefix("/text/").HandlerFunc(handlerText)
|
||||||
r.PathPrefix("/binary/").HandlerFunc(handlerBinary)
|
r.PathPrefix("/binary/").HandlerFunc(handlerBinary)
|
||||||
r.PathPrefix("/rev/").HandlerFunc(handlerRevision)
|
r.PathPrefix("/rev/").HandlerFunc(handlerRevision)
|
||||||
|
r.PathPrefix("/rev-text/").HandlerFunc(handlerRevisionText)
|
||||||
r.PathPrefix("/primitive-diff/").HandlerFunc(handlerPrimitiveDiff)
|
r.PathPrefix("/primitive-diff/").HandlerFunc(handlerPrimitiveDiff)
|
||||||
r.PathPrefix("/attachment/").HandlerFunc(handlerAttachment)
|
r.PathPrefix("/attachment/").HandlerFunc(handlerAttachment)
|
||||||
}
|
}
|
||||||
@ -64,7 +66,32 @@ func handlerPrimitiveDiff(w http.ResponseWriter, rq *http.Request) {
|
|||||||
u))
|
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) {
|
func handlerRevision(w http.ResponseWriter, rq *http.Request) {
|
||||||
util.PrepareRq(rq)
|
util.PrepareRq(rq)
|
||||||
var (
|
var (
|
||||||
|
Loading…
Reference in New Issue
Block a user