From bcaa1de6b7c5e42f7123e74428fbe295aa1605d6 Mon Sep 17 00:00:00 2001 From: bouncepaw Date: Sat, 20 Feb 2021 20:48:51 +0500 Subject: [PATCH] Move navititle, attachment block, backlinks sidebar to the new views module --- http_readers.go | 18 +-- main.go | 1 + name.go | 29 ---- shroom/backlink.go | 12 -- shroom/init.go | 3 +- shroom/view.go | 35 ----- templates/common.qtpl | 11 -- templates/common.qtpl.go | 86 +++-------- templates/readers.qtpl | 24 +-- templates/readers.qtpl.go | 266 +++++++++++++++++----------------- views/hypha.qtpl | 81 +++++++++++ views/hypha.qtpl.go | 297 ++++++++++++++++++++++++++++++++++++++ 12 files changed, 557 insertions(+), 306 deletions(-) create mode 100644 views/hypha.qtpl create mode 100644 views/hypha.qtpl.go diff --git a/http_readers.go b/http_readers.go index d99a865..9cc1351 100644 --- a/http_readers.go +++ b/http_readers.go @@ -13,11 +13,11 @@ import ( "github.com/bouncepaw/mycorrhiza/hyphae" "github.com/bouncepaw/mycorrhiza/markup" "github.com/bouncepaw/mycorrhiza/mimetype" - "github.com/bouncepaw/mycorrhiza/shroom" "github.com/bouncepaw/mycorrhiza/templates" "github.com/bouncepaw/mycorrhiza/tree" "github.com/bouncepaw/mycorrhiza/user" "github.com/bouncepaw/mycorrhiza/util" + "github.com/bouncepaw/mycorrhiza/views" ) func init() { @@ -36,9 +36,9 @@ func handlerRevision(w http.ResponseWriter, rq *http.Request) { firstSlashIndex = strings.IndexRune(shorterUrl, '/') revHash = shorterUrl[:firstSlashIndex] hyphaName = util.CanonicalName(shorterUrl[firstSlashIndex+1:]) + h = hyphae.ByName(hyphaName) contents = fmt.Sprintf(`

This hypha had no text at this revision.

`) - TextPath = hyphaName + ".myco" - textContents, err = history.FileAtRevision(TextPath, revHash) + textContents, err = history.FileAtRevision(h.TextPath, revHash) u = user.FromRequest(rq) ) if err == nil { @@ -47,8 +47,7 @@ func handlerRevision(w http.ResponseWriter, rq *http.Request) { treeHTML, subhyphae, _, _ := tree.Tree(hyphaName) page := templates.RevisionHTML( rq, - hyphaName, - naviTitle(hyphaName), + h, contents, treeHTML, subhyphae, @@ -87,7 +86,6 @@ func handlerHypha(w http.ResponseWriter, rq *http.Request) { var ( hyphaName = HyphaNameFromRq(rq, "page", "hypha") h = hyphae.ByName(hyphaName) - hasAmnt = h.Exists && h.BinaryPath != "" contents string openGraph string u = user.FromRequest(rq) @@ -101,21 +99,19 @@ func handlerHypha(w http.ResponseWriter, rq *http.Request) { openGraph = md.OpenGraphHTML() } if !os.IsNotExist(errB) { - contents = shroom.BinaryHtmlBlock(h) + contents + contents = views.AttachmentHTML(h) + contents } } treeHTML, subhyphaeHTML, prevHypha, nextHypha := tree.Tree(hyphaName) util.HTTP200Page(w, templates.BaseHTML( util.BeautifulName(hyphaName), - templates.PageHTML(rq, hyphaName, - naviTitle(hyphaName), + templates.PageHTML(rq, h, contents, treeHTML, subhyphaeHTML, - shroom.BackLinkEntriesHTML(h), prevHypha, nextHypha, - hasAmnt), + ), u, openGraph)) } diff --git a/main.go b/main.go index f35ff55..e36233d 100644 --- a/main.go +++ b/main.go @@ -1,5 +1,6 @@ //go:generate go get -u github.com/valyala/quicktemplate/qtc //go:generate qtc -dir=templates +//go:generate qtc -dir=views package main import ( diff --git a/name.go b/name.go index 739c166..7da76ba 100644 --- a/name.go +++ b/name.go @@ -1,7 +1,6 @@ package main import ( - "fmt" "log" "net/http" "strings" @@ -11,34 +10,6 @@ import ( "github.com/bouncepaw/mycorrhiza/util" ) -// naviTitle turns `canonicalName` into html string with each hypha path parts higlighted as links. -// TODO: rework as a template -func naviTitle(canonicalName string) string { - var ( - html = fmt.Sprintf(`

- %s`, util.HomePage, util.SiteNavIcon) - prevAcc = `/hypha/` - parts = strings.Split(canonicalName, "/") - rel = "up" - ) - for i, part := range parts { - if i > 0 { - html += `` - } - if i == len(parts)-1 { - rel = "bookmark" - } - html += fmt.Sprintf( - `%s`, - prevAcc+part, - rel, - util.BeautifulName(part), - ) - prevAcc += part + "/" - } - return html + "

" -} - // HyphaNameFromRq extracts hypha name from http request. You have to also pass the action which is embedded in the url or several actions. For url /hypha/hypha, the action would be "hypha". func HyphaNameFromRq(rq *http.Request, actions ...string) string { p := rq.URL.Path diff --git a/shroom/backlink.go b/shroom/backlink.go index 1d8714a..8335fc2 100644 --- a/shroom/backlink.go +++ b/shroom/backlink.go @@ -1,26 +1,14 @@ package shroom import ( - "fmt" "io/ioutil" "log" "sync" "github.com/bouncepaw/mycorrhiza/hyphae" - "github.com/bouncepaw/mycorrhiza/link" "github.com/bouncepaw/mycorrhiza/markup" - "github.com/bouncepaw/mycorrhiza/util" ) -func BackLinkEntriesHTML(h *hyphae.Hypha) (html string) { - for _, backlinkHypha := range h.BackLinks { - _ = link.Link{} - html += fmt.Sprintf(`
  • - %s`, backlinkHypha.Name, util.BeautifulName(backlinkHypha.Name)) - } - return -} - // FindAllBacklinks iterates over all hyphae that have text parts, sets their outlinks and then sets backlinks. func FindAllBacklinks() { for h := range hyphae.FilterTextHyphae(hyphae.YieldExistingHyphae()) { diff --git a/shroom/init.go b/shroom/init.go index c3c4cc1..96a6195 100644 --- a/shroom/init.go +++ b/shroom/init.go @@ -6,6 +6,7 @@ import ( "github.com/bouncepaw/mycorrhiza/hyphae" "github.com/bouncepaw/mycorrhiza/markup" "github.com/bouncepaw/mycorrhiza/util" + "github.com/bouncepaw/mycorrhiza/views" ) func init() { @@ -16,7 +17,7 @@ func init() { if h := hyphae.ByName(hyphaName); h.Exists { rawText, err = FetchTextPart(h) if h.BinaryPath != "" { - binaryBlock = BinaryHtmlBlock(h) + binaryBlock = views.AttachmentHTML(h) } } else { err = errors.New("Hypha " + hyphaName + " does not exist") diff --git a/shroom/view.go b/shroom/view.go index eca6751..05becb9 100644 --- a/shroom/view.go +++ b/shroom/view.go @@ -1,10 +1,8 @@ package shroom import ( - "fmt" "io/ioutil" "os" - "path/filepath" "github.com/bouncepaw/mycorrhiza/hyphae" "github.com/bouncepaw/mycorrhiza/markup" @@ -25,39 +23,6 @@ func FetchTextPart(h *hyphae.Hypha) (string, error) { return string(text), nil } -// binaryHtmlBlock creates an html block for binary part of the hypha. -func BinaryHtmlBlock(h *hyphae.Hypha) string { - switch filepath.Ext(h.BinaryPath) { - case ".jpg", ".gif", ".png", ".webp", ".svg", ".ico": - return fmt.Sprintf(` -
    - -
    `, h.Name) - case ".ogg", ".webm", ".mp4": - return fmt.Sprintf(` -
    - - `, h.Name) - case ".mp3": - return fmt.Sprintf(` -
    - - `, h.Name) - default: - return fmt.Sprintf(` - - `, h.Name) - } -} - func SetHeaderLinks() { if userLinksHypha := hyphae.ByName(util.HeaderLinksHypha); !userLinksHypha.Exists { util.SetDefaultHeaderLinks() diff --git a/templates/common.qtpl b/templates/common.qtpl index 6b094d1..57dea92 100644 --- a/templates/common.qtpl +++ b/templates/common.qtpl @@ -64,17 +64,6 @@ var navEntries = []navEntry{ {% endfunc %} -{% func backlinks(backlinkEntries string) %} - -{% endfunc %} - {% func subhyphaeMatrix(subhyphae string) %} {% if strings.TrimSpace(subhyphae) != "" %}
    diff --git a/templates/common.qtpl.go b/templates/common.qtpl.go index 788b784..b168af2 100644 --- a/templates/common.qtpl.go +++ b/templates/common.qtpl.go @@ -258,103 +258,57 @@ func relativeHyphae(relatives string) string { } //line templates/common.qtpl:67 -func streambacklinks(qw422016 *qt422016.Writer, backlinkEntries string) { +func streamsubhyphaeMatrix(qw422016 *qt422016.Writer, subhyphae string) { //line templates/common.qtpl:67 qw422016.N().S(` - `) -//line templates/common.qtpl:76 -} - -//line templates/common.qtpl:76 -func writebacklinks(qq422016 qtio422016.Writer, backlinkEntries string) { -//line templates/common.qtpl:76 - qw422016 := qt422016.AcquireWriter(qq422016) -//line templates/common.qtpl:76 - streambacklinks(qw422016, backlinkEntries) -//line templates/common.qtpl:76 - qt422016.ReleaseWriter(qw422016) -//line templates/common.qtpl:76 -} - -//line templates/common.qtpl:76 -func backlinks(backlinkEntries string) string { -//line templates/common.qtpl:76 - qb422016 := qt422016.AcquireByteBuffer() -//line templates/common.qtpl:76 - writebacklinks(qb422016, backlinkEntries) -//line templates/common.qtpl:76 - qs422016 := string(qb422016.B) -//line templates/common.qtpl:76 - qt422016.ReleaseByteBuffer(qb422016) -//line templates/common.qtpl:76 - return qs422016 -//line templates/common.qtpl:76 -} - -//line templates/common.qtpl:78 -func streamsubhyphaeMatrix(qw422016 *qt422016.Writer, subhyphae string) { -//line templates/common.qtpl:78 - qw422016.N().S(` -`) -//line templates/common.qtpl:79 +//line templates/common.qtpl:68 if strings.TrimSpace(subhyphae) != "" { -//line templates/common.qtpl:79 +//line templates/common.qtpl:68 qw422016.N().S(`

    Subhyphae

    `) -//line templates/common.qtpl:88 +//line templates/common.qtpl:77 } -//line templates/common.qtpl:88 +//line templates/common.qtpl:77 qw422016.N().S(` `) -//line templates/common.qtpl:89 +//line templates/common.qtpl:78 } -//line templates/common.qtpl:89 +//line templates/common.qtpl:78 func writesubhyphaeMatrix(qq422016 qtio422016.Writer, subhyphae string) { -//line templates/common.qtpl:89 +//line templates/common.qtpl:78 qw422016 := qt422016.AcquireWriter(qq422016) -//line templates/common.qtpl:89 +//line templates/common.qtpl:78 streamsubhyphaeMatrix(qw422016, subhyphae) -//line templates/common.qtpl:89 +//line templates/common.qtpl:78 qt422016.ReleaseWriter(qw422016) -//line templates/common.qtpl:89 +//line templates/common.qtpl:78 } -//line templates/common.qtpl:89 +//line templates/common.qtpl:78 func subhyphaeMatrix(subhyphae string) string { -//line templates/common.qtpl:89 +//line templates/common.qtpl:78 qb422016 := qt422016.AcquireByteBuffer() -//line templates/common.qtpl:89 +//line templates/common.qtpl:78 writesubhyphaeMatrix(qb422016, subhyphae) -//line templates/common.qtpl:89 +//line templates/common.qtpl:78 qs422016 := string(qb422016.B) -//line templates/common.qtpl:89 +//line templates/common.qtpl:78 qt422016.ReleaseByteBuffer(qb422016) -//line templates/common.qtpl:89 +//line templates/common.qtpl:78 return qs422016 -//line templates/common.qtpl:89 +//line templates/common.qtpl:78 } diff --git a/templates/readers.qtpl b/templates/readers.qtpl index 3bedb30..3a7e1e1 100644 --- a/templates/readers.qtpl +++ b/templates/readers.qtpl @@ -1,7 +1,9 @@ {% import "net/http" %} {% import "path" %} +{% import "github.com/bouncepaw/mycorrhiza/hyphae" %} {% import "github.com/bouncepaw/mycorrhiza/user" %} {% import "github.com/bouncepaw/mycorrhiza/util" %} +{% import "github.com/bouncepaw/mycorrhiza/views" %} {% func HistoryHTML(rq *http.Request, hyphaName, list string) %} {%= navHTML(rq, hyphaName, "history") %} @@ -15,13 +17,13 @@
    {% endfunc %} -{% func RevisionHTML(rq *http.Request, hyphaName, naviTitle, contents, relatives, subhyphae, revHash string) %} -{%= navHTML(rq, hyphaName, "revision", revHash) %} +{% func RevisionHTML(rq *http.Request, h *hyphae.Hypha, contents, relatives, subhyphae, revHash string) %} +{%= navHTML(rq, h.Name, "revision", revHash) %}

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

    - {%s= naviTitle %} + {%s= views.NaviTitleHTML(h) %} {%s= contents %}
    {%= subhyphaeMatrix(subhyphae) %} @@ -31,14 +33,14 @@ {% endfunc %} If `contents` == "", a helpful message is shown instead. -{% func PageHTML(rq *http.Request, hyphaName, naviTitle, contents, relatives, subhyphae, backlinkEntries, prevHyphaName, nextHyphaName string, hasAmnt bool) %} -{%= navHTML(rq, hyphaName, "page") %} +{% func PageHTML(rq *http.Request, h *hyphae.Hypha, contents, relatives, subhyphae, prevHyphaName, nextHyphaName string) %} +{%= navHTML(rq, h.Name, "page") %}
    - {%s= naviTitle %} + {%s= views.NaviTitleHTML(h) %} {% if contents == "" %} -

    This hypha has no text. Why not create it?

    +

    This hypha has no text. Why not create it?

    {% else %} {%s= contents %} {% endif %} @@ -52,11 +54,11 @@ If `contents` == "", a helpful message is shown instead. {% endif %} {% if u := user.FromRequest(rq); !user.AuthUsed || u.Group != "anon" %} -
    - {% if hasAmnt %} - Unattach current attachment? + {% if h.Exists && h.BinaryPath != "" %} + Unattach current attachment? {% endif %}
    @@ -67,6 +69,6 @@ If `contents` == "", a helpful message is shown instead. {%= subhyphaeMatrix(subhyphae) %}
    {%= relativeHyphae(relatives) %} -{%= backlinks(backlinkEntries) %} +{%= views.BackLinksHTML(h) %}
    {% endfunc %} diff --git a/templates/readers.qtpl.go b/templates/readers.qtpl.go index 5ea91a1..fed0a7f 100644 --- a/templates/readers.qtpl.go +++ b/templates/readers.qtpl.go @@ -11,256 +11,262 @@ import "net/http" import "path" //line templates/readers.qtpl:3 -import "github.com/bouncepaw/mycorrhiza/user" +import "github.com/bouncepaw/mycorrhiza/hyphae" //line templates/readers.qtpl:4 +import "github.com/bouncepaw/mycorrhiza/user" + +//line templates/readers.qtpl:5 import "github.com/bouncepaw/mycorrhiza/util" //line templates/readers.qtpl:6 +import "github.com/bouncepaw/mycorrhiza/views" + +//line templates/readers.qtpl:8 import ( qtio422016 "io" qt422016 "github.com/valyala/quicktemplate" ) -//line templates/readers.qtpl:6 +//line templates/readers.qtpl:8 var ( _ = qtio422016.Copy _ = qt422016.AcquireByteBuffer ) -//line templates/readers.qtpl:6 +//line templates/readers.qtpl:8 func StreamHistoryHTML(qw422016 *qt422016.Writer, rq *http.Request, hyphaName, list string) { -//line templates/readers.qtpl:6 +//line templates/readers.qtpl:8 qw422016.N().S(` `) -//line templates/readers.qtpl:7 +//line templates/readers.qtpl:9 streamnavHTML(qw422016, rq, hyphaName, "history") -//line templates/readers.qtpl:7 +//line templates/readers.qtpl:9 qw422016.N().S(`

    History of `) -//line templates/readers.qtpl:11 +//line templates/readers.qtpl:13 qw422016.E().S(hyphaName) -//line templates/readers.qtpl:11 +//line templates/readers.qtpl:13 qw422016.N().S(`

    `) -//line templates/readers.qtpl:12 +//line templates/readers.qtpl:14 qw422016.N().S(list) -//line templates/readers.qtpl:12 +//line templates/readers.qtpl:14 qw422016.N().S(`
    `) -//line templates/readers.qtpl:16 +//line templates/readers.qtpl:18 } -//line templates/readers.qtpl:16 +//line templates/readers.qtpl:18 func WriteHistoryHTML(qq422016 qtio422016.Writer, rq *http.Request, hyphaName, list string) { -//line templates/readers.qtpl:16 +//line templates/readers.qtpl:18 qw422016 := qt422016.AcquireWriter(qq422016) -//line templates/readers.qtpl:16 +//line templates/readers.qtpl:18 StreamHistoryHTML(qw422016, rq, hyphaName, list) -//line templates/readers.qtpl:16 +//line templates/readers.qtpl:18 qt422016.ReleaseWriter(qw422016) -//line templates/readers.qtpl:16 +//line templates/readers.qtpl:18 } -//line templates/readers.qtpl:16 +//line templates/readers.qtpl:18 func HistoryHTML(rq *http.Request, hyphaName, list string) string { -//line templates/readers.qtpl:16 +//line templates/readers.qtpl:18 qb422016 := qt422016.AcquireByteBuffer() -//line templates/readers.qtpl:16 +//line templates/readers.qtpl:18 WriteHistoryHTML(qb422016, rq, hyphaName, list) -//line templates/readers.qtpl:16 +//line templates/readers.qtpl:18 qs422016 := string(qb422016.B) -//line templates/readers.qtpl:16 +//line templates/readers.qtpl:18 qt422016.ReleaseByteBuffer(qb422016) -//line templates/readers.qtpl:16 +//line templates/readers.qtpl:18 return qs422016 -//line templates/readers.qtpl:16 +//line templates/readers.qtpl:18 } -//line templates/readers.qtpl:18 -func StreamRevisionHTML(qw422016 *qt422016.Writer, rq *http.Request, hyphaName, naviTitle, contents, relatives, subhyphae, revHash string) { -//line templates/readers.qtpl:18 +//line templates/readers.qtpl:20 +func StreamRevisionHTML(qw422016 *qt422016.Writer, rq *http.Request, h *hyphae.Hypha, contents, relatives, subhyphae, revHash string) { +//line templates/readers.qtpl:20 qw422016.N().S(` `) -//line templates/readers.qtpl:19 - streamnavHTML(qw422016, rq, hyphaName, "revision", revHash) -//line templates/readers.qtpl:19 +//line templates/readers.qtpl:21 + streamnavHTML(qw422016, rq, h.Name, "revision", revHash) +//line templates/readers.qtpl:21 qw422016.N().S(`

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

    `) -//line templates/readers.qtpl:24 - qw422016.N().S(naviTitle) -//line templates/readers.qtpl:24 +//line templates/readers.qtpl:26 + qw422016.N().S(views.NaviTitleHTML(h)) +//line templates/readers.qtpl:26 qw422016.N().S(` `) -//line templates/readers.qtpl:25 +//line templates/readers.qtpl:27 qw422016.N().S(contents) -//line templates/readers.qtpl:25 +//line templates/readers.qtpl:27 qw422016.N().S(`
    `) -//line templates/readers.qtpl:27 +//line templates/readers.qtpl:29 streamsubhyphaeMatrix(qw422016, subhyphae) -//line templates/readers.qtpl:27 +//line templates/readers.qtpl:29 qw422016.N().S(`
    `) -//line templates/readers.qtpl:29 +//line templates/readers.qtpl:31 streamrelativeHyphae(qw422016, relatives) -//line templates/readers.qtpl:29 +//line templates/readers.qtpl:31 qw422016.N().S(`
    `) -//line templates/readers.qtpl:31 +//line templates/readers.qtpl:33 } -//line templates/readers.qtpl:31 -func WriteRevisionHTML(qq422016 qtio422016.Writer, rq *http.Request, hyphaName, naviTitle, contents, relatives, subhyphae, revHash string) { -//line templates/readers.qtpl:31 +//line templates/readers.qtpl:33 +func WriteRevisionHTML(qq422016 qtio422016.Writer, rq *http.Request, h *hyphae.Hypha, contents, relatives, subhyphae, revHash string) { +//line templates/readers.qtpl:33 qw422016 := qt422016.AcquireWriter(qq422016) -//line templates/readers.qtpl:31 - StreamRevisionHTML(qw422016, rq, hyphaName, naviTitle, contents, relatives, subhyphae, revHash) -//line templates/readers.qtpl:31 +//line templates/readers.qtpl:33 + StreamRevisionHTML(qw422016, rq, h, contents, relatives, subhyphae, revHash) +//line templates/readers.qtpl:33 qt422016.ReleaseWriter(qw422016) -//line templates/readers.qtpl:31 +//line templates/readers.qtpl:33 } -//line templates/readers.qtpl:31 -func RevisionHTML(rq *http.Request, hyphaName, naviTitle, contents, relatives, subhyphae, revHash string) string { -//line templates/readers.qtpl:31 +//line templates/readers.qtpl:33 +func RevisionHTML(rq *http.Request, h *hyphae.Hypha, contents, relatives, subhyphae, revHash string) string { +//line templates/readers.qtpl:33 qb422016 := qt422016.AcquireByteBuffer() -//line templates/readers.qtpl:31 - WriteRevisionHTML(qb422016, rq, hyphaName, naviTitle, contents, relatives, subhyphae, revHash) -//line templates/readers.qtpl:31 +//line templates/readers.qtpl:33 + WriteRevisionHTML(qb422016, rq, h, contents, relatives, subhyphae, revHash) +//line templates/readers.qtpl:33 qs422016 := string(qb422016.B) -//line templates/readers.qtpl:31 +//line templates/readers.qtpl:33 qt422016.ReleaseByteBuffer(qb422016) -//line templates/readers.qtpl:31 +//line templates/readers.qtpl:33 return qs422016 -//line templates/readers.qtpl:31 +//line templates/readers.qtpl:33 } // If `contents` == "", a helpful message is shown instead. -//line templates/readers.qtpl:34 -func StreamPageHTML(qw422016 *qt422016.Writer, rq *http.Request, hyphaName, naviTitle, contents, relatives, subhyphae, backlinkEntries, prevHyphaName, nextHyphaName string, hasAmnt bool) { -//line templates/readers.qtpl:34 +//line templates/readers.qtpl:36 +func StreamPageHTML(qw422016 *qt422016.Writer, rq *http.Request, h *hyphae.Hypha, contents, relatives, subhyphae, prevHyphaName, nextHyphaName string) { +//line templates/readers.qtpl:36 qw422016.N().S(` `) -//line templates/readers.qtpl:35 - streamnavHTML(qw422016, rq, hyphaName, "page") -//line templates/readers.qtpl:35 +//line templates/readers.qtpl:37 + streamnavHTML(qw422016, rq, h.Name, "page") +//line templates/readers.qtpl:37 qw422016.N().S(`
    `) -//line templates/readers.qtpl:39 - qw422016.N().S(naviTitle) -//line templates/readers.qtpl:39 +//line templates/readers.qtpl:41 + qw422016.N().S(views.NaviTitleHTML(h)) +//line templates/readers.qtpl:41 qw422016.N().S(` `) -//line templates/readers.qtpl:40 +//line templates/readers.qtpl:42 if contents == "" { -//line templates/readers.qtpl:40 +//line templates/readers.qtpl:42 qw422016.N().S(`

    This hypha has no text. Why not create it?

    `) -//line templates/readers.qtpl:42 +//line templates/readers.qtpl:44 } else { -//line templates/readers.qtpl:42 +//line templates/readers.qtpl:44 qw422016.N().S(` `) -//line templates/readers.qtpl:43 +//line templates/readers.qtpl:45 qw422016.N().S(contents) -//line templates/readers.qtpl:43 +//line templates/readers.qtpl:45 qw422016.N().S(` `) -//line templates/readers.qtpl:44 +//line templates/readers.qtpl:46 } -//line templates/readers.qtpl:44 +//line templates/readers.qtpl:46 qw422016.N().S(`
    `) -//line templates/readers.qtpl:47 +//line templates/readers.qtpl:49 if prevHyphaName != "" { -//line templates/readers.qtpl:47 +//line templates/readers.qtpl:49 qw422016.N().S(` `) -//line templates/readers.qtpl:49 +//line templates/readers.qtpl:51 } -//line templates/readers.qtpl:49 +//line templates/readers.qtpl:51 qw422016.N().S(` `) -//line templates/readers.qtpl:50 +//line templates/readers.qtpl:52 if nextHyphaName != "" { -//line templates/readers.qtpl:50 +//line templates/readers.qtpl:52 qw422016.N().S(` `) -//line templates/readers.qtpl:52 +//line templates/readers.qtpl:54 } -//line templates/readers.qtpl:52 +//line templates/readers.qtpl:54 qw422016.N().S(`
    `) -//line templates/readers.qtpl:54 +//line templates/readers.qtpl:56 if u := user.FromRequest(rq); !user.AuthUsed || u.Group != "anon" { -//line templates/readers.qtpl:54 +//line templates/readers.qtpl:56 qw422016.N().S(` `) -//line templates/readers.qtpl:58 - if hasAmnt { -//line templates/readers.qtpl:58 +//line templates/readers.qtpl:60 + if h.Exists && h.BinaryPath != "" { +//line templates/readers.qtpl:60 qw422016.N().S(` Unattach current attachment? `) -//line templates/readers.qtpl:60 +//line templates/readers.qtpl:62 } -//line templates/readers.qtpl:60 +//line templates/readers.qtpl:62 qw422016.N().S(`
    @@ -268,53 +274,53 @@ func StreamPageHTML(qw422016 *qt422016.Writer, rq *http.Request, hyphaName, navi `) -//line templates/readers.qtpl:66 +//line templates/readers.qtpl:68 } -//line templates/readers.qtpl:66 +//line templates/readers.qtpl:68 qw422016.N().S(` `) -//line templates/readers.qtpl:67 +//line templates/readers.qtpl:69 streamsubhyphaeMatrix(qw422016, subhyphae) -//line templates/readers.qtpl:67 +//line templates/readers.qtpl:69 qw422016.N().S(`
    `) -//line templates/readers.qtpl:69 +//line templates/readers.qtpl:71 streamrelativeHyphae(qw422016, relatives) -//line templates/readers.qtpl:69 +//line templates/readers.qtpl:71 qw422016.N().S(` `) -//line templates/readers.qtpl:70 - streambacklinks(qw422016, backlinkEntries) -//line templates/readers.qtpl:70 +//line templates/readers.qtpl:72 + views.StreamBackLinksHTML(qw422016, h) +//line templates/readers.qtpl:72 qw422016.N().S(`
    `) -//line templates/readers.qtpl:72 +//line templates/readers.qtpl:74 } -//line templates/readers.qtpl:72 -func WritePageHTML(qq422016 qtio422016.Writer, rq *http.Request, hyphaName, naviTitle, contents, relatives, subhyphae, backlinkEntries, prevHyphaName, nextHyphaName string, hasAmnt bool) { -//line templates/readers.qtpl:72 +//line templates/readers.qtpl:74 +func WritePageHTML(qq422016 qtio422016.Writer, rq *http.Request, h *hyphae.Hypha, contents, relatives, subhyphae, prevHyphaName, nextHyphaName string) { +//line templates/readers.qtpl:74 qw422016 := qt422016.AcquireWriter(qq422016) -//line templates/readers.qtpl:72 - StreamPageHTML(qw422016, rq, hyphaName, naviTitle, contents, relatives, subhyphae, backlinkEntries, prevHyphaName, nextHyphaName, hasAmnt) -//line templates/readers.qtpl:72 +//line templates/readers.qtpl:74 + StreamPageHTML(qw422016, rq, h, contents, relatives, subhyphae, prevHyphaName, nextHyphaName) +//line templates/readers.qtpl:74 qt422016.ReleaseWriter(qw422016) -//line templates/readers.qtpl:72 +//line templates/readers.qtpl:74 } -//line templates/readers.qtpl:72 -func PageHTML(rq *http.Request, hyphaName, naviTitle, contents, relatives, subhyphae, backlinkEntries, prevHyphaName, nextHyphaName string, hasAmnt bool) string { -//line templates/readers.qtpl:72 +//line templates/readers.qtpl:74 +func PageHTML(rq *http.Request, h *hyphae.Hypha, contents, relatives, subhyphae, prevHyphaName, nextHyphaName string) string { +//line templates/readers.qtpl:74 qb422016 := qt422016.AcquireByteBuffer() -//line templates/readers.qtpl:72 - WritePageHTML(qb422016, rq, hyphaName, naviTitle, contents, relatives, subhyphae, backlinkEntries, prevHyphaName, nextHyphaName, hasAmnt) -//line templates/readers.qtpl:72 +//line templates/readers.qtpl:74 + WritePageHTML(qb422016, rq, h, contents, relatives, subhyphae, prevHyphaName, nextHyphaName) +//line templates/readers.qtpl:74 qs422016 := string(qb422016.B) -//line templates/readers.qtpl:72 +//line templates/readers.qtpl:74 qt422016.ReleaseByteBuffer(qb422016) -//line templates/readers.qtpl:72 +//line templates/readers.qtpl:74 return qs422016 -//line templates/readers.qtpl:72 +//line templates/readers.qtpl:74 } diff --git a/views/hypha.qtpl b/views/hypha.qtpl new file mode 100644 index 0000000..a2d74ba --- /dev/null +++ b/views/hypha.qtpl @@ -0,0 +1,81 @@ +{% import "path/filepath" %} +{% import "strings" %} +{% import "github.com/bouncepaw/mycorrhiza/hyphae" %} +{% import "github.com/bouncepaw/mycorrhiza/util" %} + +{% func NaviTitleHTML(h *hyphae.Hypha) %} +{% code + var ( + prevAcc = "/hypha/" + parts = strings.Split(h.Name, "/") + ) +%} +

    +{% stripspace %} + + {%-s= util.SiteNavIcon -%} + + + + {% for i, part := range parts %} + {% if i > 0 %} + + {% endif %} + + + {%s= util.BeautifulName(part) %} + + {% code prevAcc += part + "/" %} + {% endfor %} +{% endstripspace %} +

    +{% endfunc %} + +{% func BackLinksHTML(h *hyphae.Hypha) %} + +{% endfunc %} + +{% func AttachmentHTML(h *hyphae.Hypha) %} + {% switch filepath.Ext(h.BinaryPath) %} + + {% case ".jpg", ".gif", ".png", ".webp", ".svg", ".ico" %} +
    + +
    + + {% case ".ogg", ".webm", ".mp4" %} +
    + +
    + + {% case ".mp3" %} +
    + +
    + + {% default %} + +{% endswitch %} +{% endfunc %} diff --git a/views/hypha.qtpl.go b/views/hypha.qtpl.go new file mode 100644 index 0000000..499b9aa --- /dev/null +++ b/views/hypha.qtpl.go @@ -0,0 +1,297 @@ +// Code generated by qtc from "hypha.qtpl". DO NOT EDIT. +// See https://github.com/valyala/quicktemplate for details. + +//line views/hypha.qtpl:1 +package views + +//line views/hypha.qtpl:1 +import "path/filepath" + +//line views/hypha.qtpl:2 +import "strings" + +//line views/hypha.qtpl:3 +import "github.com/bouncepaw/mycorrhiza/hyphae" + +//line views/hypha.qtpl:4 +import "github.com/bouncepaw/mycorrhiza/util" + +//line views/hypha.qtpl:6 +import ( + qtio422016 "io" + + qt422016 "github.com/valyala/quicktemplate" +) + +//line views/hypha.qtpl:6 +var ( + _ = qtio422016.Copy + _ = qt422016.AcquireByteBuffer +) + +//line views/hypha.qtpl:6 +func StreamNaviTitleHTML(qw422016 *qt422016.Writer, h *hyphae.Hypha) { +//line views/hypha.qtpl:6 + qw422016.N().S(` +`) +//line views/hypha.qtpl:8 + var ( + prevAcc = "/hypha/" + parts = strings.Split(h.Name, "/") + ) + +//line views/hypha.qtpl:12 + qw422016.N().S(` +

    +`) +//line views/hypha.qtpl:14 + qw422016.N().S(``) +//line views/hypha.qtpl:16 + qw422016.N().S(util.SiteNavIcon) +//line views/hypha.qtpl:16 + qw422016.N().S(``) +//line views/hypha.qtpl:20 + for i, part := range parts { +//line views/hypha.qtpl:21 + if i > 0 { +//line views/hypha.qtpl:21 + qw422016.N().S(``) +//line views/hypha.qtpl:23 + } +//line views/hypha.qtpl:23 + qw422016.N().S(``) +//line views/hypha.qtpl:27 + qw422016.N().S(util.BeautifulName(part)) +//line views/hypha.qtpl:27 + qw422016.N().S(``) +//line views/hypha.qtpl:29 + prevAcc += part + "/" + +//line views/hypha.qtpl:30 + } +//line views/hypha.qtpl:31 + qw422016.N().S(` +

    +`) +//line views/hypha.qtpl:33 +} + +//line views/hypha.qtpl:33 +func WriteNaviTitleHTML(qq422016 qtio422016.Writer, h *hyphae.Hypha) { +//line views/hypha.qtpl:33 + qw422016 := qt422016.AcquireWriter(qq422016) +//line views/hypha.qtpl:33 + StreamNaviTitleHTML(qw422016, h) +//line views/hypha.qtpl:33 + qt422016.ReleaseWriter(qw422016) +//line views/hypha.qtpl:33 +} + +//line views/hypha.qtpl:33 +func NaviTitleHTML(h *hyphae.Hypha) string { +//line views/hypha.qtpl:33 + qb422016 := qt422016.AcquireByteBuffer() +//line views/hypha.qtpl:33 + WriteNaviTitleHTML(qb422016, h) +//line views/hypha.qtpl:33 + qs422016 := string(qb422016.B) +//line views/hypha.qtpl:33 + qt422016.ReleaseByteBuffer(qb422016) +//line views/hypha.qtpl:33 + return qs422016 +//line views/hypha.qtpl:33 +} + +//line views/hypha.qtpl:35 +func StreamBackLinksHTML(qw422016 *qt422016.Writer, h *hyphae.Hypha) { +//line views/hypha.qtpl:35 + qw422016.N().S(` + +`) +//line views/hypha.qtpl:50 +} + +//line views/hypha.qtpl:50 +func WriteBackLinksHTML(qq422016 qtio422016.Writer, h *hyphae.Hypha) { +//line views/hypha.qtpl:50 + qw422016 := qt422016.AcquireWriter(qq422016) +//line views/hypha.qtpl:50 + StreamBackLinksHTML(qw422016, h) +//line views/hypha.qtpl:50 + qt422016.ReleaseWriter(qw422016) +//line views/hypha.qtpl:50 +} + +//line views/hypha.qtpl:50 +func BackLinksHTML(h *hyphae.Hypha) string { +//line views/hypha.qtpl:50 + qb422016 := qt422016.AcquireByteBuffer() +//line views/hypha.qtpl:50 + WriteBackLinksHTML(qb422016, h) +//line views/hypha.qtpl:50 + qs422016 := string(qb422016.B) +//line views/hypha.qtpl:50 + qt422016.ReleaseByteBuffer(qb422016) +//line views/hypha.qtpl:50 + return qs422016 +//line views/hypha.qtpl:50 +} + +//line views/hypha.qtpl:52 +func StreamAttachmentHTML(qw422016 *qt422016.Writer, h *hyphae.Hypha) { +//line views/hypha.qtpl:52 + qw422016.N().S(` + `) +//line views/hypha.qtpl:53 + switch filepath.Ext(h.BinaryPath) { +//line views/hypha.qtpl:55 + case ".jpg", ".gif", ".png", ".webp", ".svg", ".ico": +//line views/hypha.qtpl:55 + qw422016.N().S(` +
    + +
    + + `) +//line views/hypha.qtpl:60 + case ".ogg", ".webm", ".mp4": +//line views/hypha.qtpl:60 + qw422016.N().S(` +
    + +
    + + `) +//line views/hypha.qtpl:68 + case ".mp3": +//line views/hypha.qtpl:68 + qw422016.N().S(` +
    + +
    + + `) +//line views/hypha.qtpl:76 + default: +//line views/hypha.qtpl:76 + qw422016.N().S(` + +`) +//line views/hypha.qtpl:80 + } +//line views/hypha.qtpl:80 + qw422016.N().S(` +`) +//line views/hypha.qtpl:81 +} + +//line views/hypha.qtpl:81 +func WriteAttachmentHTML(qq422016 qtio422016.Writer, h *hyphae.Hypha) { +//line views/hypha.qtpl:81 + qw422016 := qt422016.AcquireWriter(qq422016) +//line views/hypha.qtpl:81 + StreamAttachmentHTML(qw422016, h) +//line views/hypha.qtpl:81 + qt422016.ReleaseWriter(qw422016) +//line views/hypha.qtpl:81 +} + +//line views/hypha.qtpl:81 +func AttachmentHTML(h *hyphae.Hypha) string { +//line views/hypha.qtpl:81 + qb422016 := qt422016.AcquireByteBuffer() +//line views/hypha.qtpl:81 + WriteAttachmentHTML(qb422016, h) +//line views/hypha.qtpl:81 + qs422016 := string(qb422016.B) +//line views/hypha.qtpl:81 + qt422016.ReleaseByteBuffer(qb422016) +//line views/hypha.qtpl:81 + return qs422016 +//line views/hypha.qtpl:81 +}