From bea80887f45d5930e293cb34dee62ce885428b59 Mon Sep 17 00:00:00 2001 From: Timur Ismagilov Date: Mon, 12 Jul 2021 14:58:20 +0500 Subject: [PATCH] Add some styling to help Now it looks more like usual hyphae --- help/en/attachment.myco | 2 +- help/en/hypha.myco | 4 +- help/en/index.myco | 11 +- views/stuff.qtpl | 36 ++++ views/stuff.qtpl.go | 413 ++++++++++++++++++++++++++-------------- web/stuff.go | 28 ++- 6 files changed, 346 insertions(+), 148 deletions(-) diff --git a/help/en/attachment.myco b/help/en/attachment.myco index 2f866e9..c55bb14 100644 --- a/help/en/attachment.myco +++ b/help/en/attachment.myco @@ -1,4 +1,4 @@ -# Attachment +# Help: Attachment In hyphae, an **attachment** is some content represented by something that is not [[/help/en/mycomarkup | Mycomarkup]]. Usually, an image, a video, or an audio. ## Supported attachment types diff --git a/help/en/hypha.myco b/help/en/hypha.myco index 51b9cb9..97281da 100644 --- a/help/en/hypha.myco +++ b/help/en/hypha.myco @@ -1,5 +1,5 @@ -# Hypha -**Hypha** (//plural:// hyphae) is the main content unit used in Mycorrhiza Wiki. +# Help: Hypha +A **hypha** (//plural:// hyphae) is the main content unit used in Mycorrhiza Wiki. ## The structure of hypha A hypha consists of two parts: diff --git a/help/en/index.myco b/help/en/index.myco index c0c5062..50a5921 100644 --- a/help/en/index.myco +++ b/help/en/index.myco @@ -1,9 +1,12 @@ +# Help This is Mycorrhiza Wiki built-in documentation. Hope you are doing well ☺️ -Here are the topics covered by the documentation: -* [[/help/en/hypha | Hypha]] -** [[/help/en/attachment | Attachment]] +See the section on the right (if you are on computer) or below (if you are on mobile) to see what topics are covered by the documentation. -Thanks for reading! \ No newline at end of file +Thanks for reading! + +---- + +You might want to contribute to the documentation. Open a pull-request on [[https://github.com/bouncepaw/mycorrhiza | GitHub]] if you know how to. \ No newline at end of file diff --git a/views/stuff.qtpl b/views/stuff.qtpl index 0bc1d0b..ddd18d1 100644 --- a/views/stuff.qtpl +++ b/views/stuff.qtpl @@ -44,6 +44,42 @@ {% endfunc %} +{% func HelpHTML(content string) %} +
+
+
+ {%s= content %} +
+
+{%s= helpTopicsHTML() %} +
+{% endfunc %} + +{% func HelpEmptyErrorHTML() %} +

This entry does not exist!

+

Try finding a different entry that would help you.

+

If you want to write this entry by yourself, consider contributing to Mycorrhiza Wiki directly.

+{% endfunc %} + +{% func helpTopicsHTML() %} + +{% endfunc %} + {% func UserListHTML() %}
diff --git a/views/stuff.qtpl.go b/views/stuff.qtpl.go index ba8a00d..487218f 100644 --- a/views/stuff.qtpl.go +++ b/views/stuff.qtpl.go @@ -142,14 +142,151 @@ func BaseHTML(title, body string, u *user.User, headElements ...string) string { } //line views/stuff.qtpl:47 -func StreamUserListHTML(qw422016 *qt422016.Writer) { +func StreamHelpHTML(qw422016 *qt422016.Writer, content string) { //line views/stuff.qtpl:47 qw422016.N().S(`
+
+
+ `) +//line views/stuff.qtpl:51 + qw422016.N().S(content) +//line views/stuff.qtpl:51 + qw422016.N().S(` +
+
+`) +//line views/stuff.qtpl:54 + qw422016.N().S(helpTopicsHTML()) +//line views/stuff.qtpl:54 + qw422016.N().S(` +
+`) +//line views/stuff.qtpl:56 +} + +//line views/stuff.qtpl:56 +func WriteHelpHTML(qq422016 qtio422016.Writer, content string) { +//line views/stuff.qtpl:56 + qw422016 := qt422016.AcquireWriter(qq422016) +//line views/stuff.qtpl:56 + StreamHelpHTML(qw422016, content) +//line views/stuff.qtpl:56 + qt422016.ReleaseWriter(qw422016) +//line views/stuff.qtpl:56 +} + +//line views/stuff.qtpl:56 +func HelpHTML(content string) string { +//line views/stuff.qtpl:56 + qb422016 := qt422016.AcquireByteBuffer() +//line views/stuff.qtpl:56 + WriteHelpHTML(qb422016, content) +//line views/stuff.qtpl:56 + qs422016 := string(qb422016.B) +//line views/stuff.qtpl:56 + qt422016.ReleaseByteBuffer(qb422016) +//line views/stuff.qtpl:56 + return qs422016 +//line views/stuff.qtpl:56 +} + +//line views/stuff.qtpl:58 +func StreamHelpEmptyErrorHTML(qw422016 *qt422016.Writer) { +//line views/stuff.qtpl:58 + qw422016.N().S(` +

This entry does not exist!

+

Try finding a different entry that would help you.

+

If you want to write this entry by yourself, consider contributing to Mycorrhiza Wiki directly.

+`) +//line views/stuff.qtpl:62 +} + +//line views/stuff.qtpl:62 +func WriteHelpEmptyErrorHTML(qq422016 qtio422016.Writer) { +//line views/stuff.qtpl:62 + qw422016 := qt422016.AcquireWriter(qq422016) +//line views/stuff.qtpl:62 + StreamHelpEmptyErrorHTML(qw422016) +//line views/stuff.qtpl:62 + qt422016.ReleaseWriter(qw422016) +//line views/stuff.qtpl:62 +} + +//line views/stuff.qtpl:62 +func HelpEmptyErrorHTML() string { +//line views/stuff.qtpl:62 + qb422016 := qt422016.AcquireByteBuffer() +//line views/stuff.qtpl:62 + WriteHelpEmptyErrorHTML(qb422016) +//line views/stuff.qtpl:62 + qs422016 := string(qb422016.B) +//line views/stuff.qtpl:62 + qt422016.ReleaseByteBuffer(qb422016) +//line views/stuff.qtpl:62 + return qs422016 +//line views/stuff.qtpl:62 +} + +//line views/stuff.qtpl:64 +func streamhelpTopicsHTML(qw422016 *qt422016.Writer) { +//line views/stuff.qtpl:64 + qw422016.N().S(` + +`) +//line views/stuff.qtpl:81 +} + +//line views/stuff.qtpl:81 +func writehelpTopicsHTML(qq422016 qtio422016.Writer) { +//line views/stuff.qtpl:81 + qw422016 := qt422016.AcquireWriter(qq422016) +//line views/stuff.qtpl:81 + streamhelpTopicsHTML(qw422016) +//line views/stuff.qtpl:81 + qt422016.ReleaseWriter(qw422016) +//line views/stuff.qtpl:81 +} + +//line views/stuff.qtpl:81 +func helpTopicsHTML() string { +//line views/stuff.qtpl:81 + qb422016 := qt422016.AcquireByteBuffer() +//line views/stuff.qtpl:81 + writehelpTopicsHTML(qb422016) +//line views/stuff.qtpl:81 + qs422016 := string(qb422016.B) +//line views/stuff.qtpl:81 + qt422016.ReleaseByteBuffer(qb422016) +//line views/stuff.qtpl:81 + return qs422016 +//line views/stuff.qtpl:81 +} + +//line views/stuff.qtpl:83 +func StreamUserListHTML(qw422016 *qt422016.Writer) { +//line views/stuff.qtpl:83 + qw422016.N().S(` +

List of users

`) -//line views/stuff.qtpl:52 +//line views/stuff.qtpl:88 var ( admins = make([]string, 0) moderators = make([]string, 0) @@ -166,345 +303,345 @@ func StreamUserListHTML(qw422016 *qt422016.Writer) { } } -//line views/stuff.qtpl:67 +//line views/stuff.qtpl:103 qw422016.N().S(`

Admins

    `) -//line views/stuff.qtpl:70 +//line views/stuff.qtpl:106 for _, name := range admins { -//line views/stuff.qtpl:70 +//line views/stuff.qtpl:106 qw422016.N().S(`
  1. `) -//line views/stuff.qtpl:71 +//line views/stuff.qtpl:107 qw422016.E().S(name) -//line views/stuff.qtpl:71 +//line views/stuff.qtpl:107 qw422016.N().S(`
  2. `) -//line views/stuff.qtpl:72 +//line views/stuff.qtpl:108 } -//line views/stuff.qtpl:72 +//line views/stuff.qtpl:108 qw422016.N().S(`

Moderators

    `) -//line views/stuff.qtpl:76 +//line views/stuff.qtpl:112 for _, name := range moderators { -//line views/stuff.qtpl:76 +//line views/stuff.qtpl:112 qw422016.N().S(`
  1. `) -//line views/stuff.qtpl:77 +//line views/stuff.qtpl:113 qw422016.E().S(name) -//line views/stuff.qtpl:77 +//line views/stuff.qtpl:113 qw422016.N().S(`
  2. `) -//line views/stuff.qtpl:78 +//line views/stuff.qtpl:114 } -//line views/stuff.qtpl:78 +//line views/stuff.qtpl:114 qw422016.N().S(`

Editors

    `) -//line views/stuff.qtpl:82 +//line views/stuff.qtpl:118 for _, name := range editors { -//line views/stuff.qtpl:82 +//line views/stuff.qtpl:118 qw422016.N().S(`
  1. `) -//line views/stuff.qtpl:83 +//line views/stuff.qtpl:119 qw422016.E().S(name) -//line views/stuff.qtpl:83 +//line views/stuff.qtpl:119 qw422016.N().S(`
  2. `) -//line views/stuff.qtpl:84 +//line views/stuff.qtpl:120 } -//line views/stuff.qtpl:84 +//line views/stuff.qtpl:120 qw422016.N().S(`
`) -//line views/stuff.qtpl:88 +//line views/stuff.qtpl:124 } -//line views/stuff.qtpl:88 +//line views/stuff.qtpl:124 func WriteUserListHTML(qq422016 qtio422016.Writer) { -//line views/stuff.qtpl:88 +//line views/stuff.qtpl:124 qw422016 := qt422016.AcquireWriter(qq422016) -//line views/stuff.qtpl:88 +//line views/stuff.qtpl:124 StreamUserListHTML(qw422016) -//line views/stuff.qtpl:88 +//line views/stuff.qtpl:124 qt422016.ReleaseWriter(qw422016) -//line views/stuff.qtpl:88 +//line views/stuff.qtpl:124 } -//line views/stuff.qtpl:88 +//line views/stuff.qtpl:124 func UserListHTML() string { -//line views/stuff.qtpl:88 +//line views/stuff.qtpl:124 qb422016 := qt422016.AcquireByteBuffer() -//line views/stuff.qtpl:88 +//line views/stuff.qtpl:124 WriteUserListHTML(qb422016) -//line views/stuff.qtpl:88 +//line views/stuff.qtpl:124 qs422016 := string(qb422016.B) -//line views/stuff.qtpl:88 +//line views/stuff.qtpl:124 qt422016.ReleaseByteBuffer(qb422016) -//line views/stuff.qtpl:88 +//line views/stuff.qtpl:124 return qs422016 -//line views/stuff.qtpl:88 +//line views/stuff.qtpl:124 } -//line views/stuff.qtpl:90 +//line views/stuff.qtpl:126 func StreamHyphaListHTML(qw422016 *qt422016.Writer) { -//line views/stuff.qtpl:90 +//line views/stuff.qtpl:126 qw422016.N().S(`

List of hyphae

This wiki has `) -//line views/stuff.qtpl:94 +//line views/stuff.qtpl:130 qw422016.N().D(hyphae.Count()) -//line views/stuff.qtpl:94 +//line views/stuff.qtpl:130 qw422016.N().S(` hyphae.

    `) -//line views/stuff.qtpl:96 +//line views/stuff.qtpl:132 for h := range hyphae.YieldExistingHyphae() { -//line views/stuff.qtpl:96 +//line views/stuff.qtpl:132 qw422016.N().S(`
  • `) -//line views/stuff.qtpl:98 +//line views/stuff.qtpl:134 qw422016.E().S(util.BeautifulName(h.Name)) -//line views/stuff.qtpl:98 +//line views/stuff.qtpl:134 qw422016.N().S(` `) -//line views/stuff.qtpl:99 +//line views/stuff.qtpl:135 if h.BinaryPath != "" { -//line views/stuff.qtpl:99 +//line views/stuff.qtpl:135 qw422016.N().S(` `) -//line views/stuff.qtpl:100 +//line views/stuff.qtpl:136 qw422016.E().S(filepath.Ext(h.BinaryPath)[1:]) -//line views/stuff.qtpl:100 +//line views/stuff.qtpl:136 qw422016.N().S(` `) -//line views/stuff.qtpl:101 +//line views/stuff.qtpl:137 } -//line views/stuff.qtpl:101 +//line views/stuff.qtpl:137 qw422016.N().S(`
  • `) -//line views/stuff.qtpl:103 +//line views/stuff.qtpl:139 } -//line views/stuff.qtpl:103 +//line views/stuff.qtpl:139 qw422016.N().S(`
`) -//line views/stuff.qtpl:107 +//line views/stuff.qtpl:143 } -//line views/stuff.qtpl:107 +//line views/stuff.qtpl:143 func WriteHyphaListHTML(qq422016 qtio422016.Writer) { -//line views/stuff.qtpl:107 +//line views/stuff.qtpl:143 qw422016 := qt422016.AcquireWriter(qq422016) -//line views/stuff.qtpl:107 +//line views/stuff.qtpl:143 StreamHyphaListHTML(qw422016) -//line views/stuff.qtpl:107 +//line views/stuff.qtpl:143 qt422016.ReleaseWriter(qw422016) -//line views/stuff.qtpl:107 +//line views/stuff.qtpl:143 } -//line views/stuff.qtpl:107 +//line views/stuff.qtpl:143 func HyphaListHTML() string { -//line views/stuff.qtpl:107 +//line views/stuff.qtpl:143 qb422016 := qt422016.AcquireByteBuffer() -//line views/stuff.qtpl:107 +//line views/stuff.qtpl:143 WriteHyphaListHTML(qb422016) -//line views/stuff.qtpl:107 +//line views/stuff.qtpl:143 qs422016 := string(qb422016.B) -//line views/stuff.qtpl:107 +//line views/stuff.qtpl:143 qt422016.ReleaseByteBuffer(qb422016) -//line views/stuff.qtpl:107 +//line views/stuff.qtpl:143 return qs422016 -//line views/stuff.qtpl:107 +//line views/stuff.qtpl:143 } -//line views/stuff.qtpl:109 +//line views/stuff.qtpl:145 func StreamAboutHTML(qw422016 *qt422016.Writer) { -//line views/stuff.qtpl:109 +//line views/stuff.qtpl:145 qw422016.N().S(`

About `) -//line views/stuff.qtpl:113 +//line views/stuff.qtpl:149 qw422016.E().S(cfg.WikiName) -//line views/stuff.qtpl:113 +//line views/stuff.qtpl:149 qw422016.N().S(`

See /list for information about hyphae on this wiki.

`) -//line views/stuff.qtpl:131 +//line views/stuff.qtpl:167 } -//line views/stuff.qtpl:131 +//line views/stuff.qtpl:167 func WriteAboutHTML(qq422016 qtio422016.Writer) { -//line views/stuff.qtpl:131 +//line views/stuff.qtpl:167 qw422016 := qt422016.AcquireWriter(qq422016) -//line views/stuff.qtpl:131 +//line views/stuff.qtpl:167 StreamAboutHTML(qw422016) -//line views/stuff.qtpl:131 +//line views/stuff.qtpl:167 qt422016.ReleaseWriter(qw422016) -//line views/stuff.qtpl:131 +//line views/stuff.qtpl:167 } -//line views/stuff.qtpl:131 +//line views/stuff.qtpl:167 func AboutHTML() string { -//line views/stuff.qtpl:131 +//line views/stuff.qtpl:167 qb422016 := qt422016.AcquireByteBuffer() -//line views/stuff.qtpl:131 +//line views/stuff.qtpl:167 WriteAboutHTML(qb422016) -//line views/stuff.qtpl:131 +//line views/stuff.qtpl:167 qs422016 := string(qb422016.B) -//line views/stuff.qtpl:131 +//line views/stuff.qtpl:167 qt422016.ReleaseByteBuffer(qb422016) -//line views/stuff.qtpl:131 +//line views/stuff.qtpl:167 return qs422016 -//line views/stuff.qtpl:131 +//line views/stuff.qtpl:167 } -//line views/stuff.qtpl:133 +//line views/stuff.qtpl:169 func StreamCommonScripts(qw422016 *qt422016.Writer) { -//line views/stuff.qtpl:133 +//line views/stuff.qtpl:169 qw422016.N().S(` `) -//line views/stuff.qtpl:134 +//line views/stuff.qtpl:170 for _, scriptPath := range cfg.CommonScripts { -//line views/stuff.qtpl:134 +//line views/stuff.qtpl:170 qw422016.N().S(` `) -//line views/stuff.qtpl:136 +//line views/stuff.qtpl:172 } -//line views/stuff.qtpl:136 +//line views/stuff.qtpl:172 qw422016.N().S(` `) -//line views/stuff.qtpl:137 +//line views/stuff.qtpl:173 } -//line views/stuff.qtpl:137 +//line views/stuff.qtpl:173 func WriteCommonScripts(qq422016 qtio422016.Writer) { -//line views/stuff.qtpl:137 +//line views/stuff.qtpl:173 qw422016 := qt422016.AcquireWriter(qq422016) -//line views/stuff.qtpl:137 +//line views/stuff.qtpl:173 StreamCommonScripts(qw422016) -//line views/stuff.qtpl:137 +//line views/stuff.qtpl:173 qt422016.ReleaseWriter(qw422016) -//line views/stuff.qtpl:137 +//line views/stuff.qtpl:173 } -//line views/stuff.qtpl:137 +//line views/stuff.qtpl:173 func CommonScripts() string { -//line views/stuff.qtpl:137 +//line views/stuff.qtpl:173 qb422016 := qt422016.AcquireByteBuffer() -//line views/stuff.qtpl:137 +//line views/stuff.qtpl:173 WriteCommonScripts(qb422016) -//line views/stuff.qtpl:137 +//line views/stuff.qtpl:173 qs422016 := string(qb422016.B) -//line views/stuff.qtpl:137 +//line views/stuff.qtpl:173 qt422016.ReleaseByteBuffer(qb422016) -//line views/stuff.qtpl:137 +//line views/stuff.qtpl:173 return qs422016 -//line views/stuff.qtpl:137 +//line views/stuff.qtpl:173 } diff --git a/web/stuff.go b/web/stuff.go index b757a97..a914ea5 100644 --- a/web/stuff.go +++ b/web/stuff.go @@ -9,6 +9,7 @@ import ( "log" "math/rand" "net/http" + "strings" "github.com/bouncepaw/mycorrhiza/cfg" "github.com/bouncepaw/mycorrhiza/files" @@ -39,9 +40,24 @@ func handlerHelp(w http.ResponseWriter, rq *http.Request) { } content, err := help.Get(rq.URL.Path[6:]) // Drop /help/ + if err != nil && strings.HasPrefix(err.Error(), "open") { + w.WriteHeader(http.StatusNotFound) + _, _ = io.WriteString( + w, + views.BaseHTML("Entry not found", + views.HelpHTML(views.HelpEmptyErrorHTML()), + user.FromRequest(rq)), + ) + return + } if err != nil { - // TODO: proper error reporting that makes sense - httpErr(w, http.StatusForbidden, cfg.HomeHypha, err.Error(), err.Error()) + w.WriteHeader(http.StatusInternalServerError) + _, _ = io.WriteString( + w, + views.BaseHTML(err.Error(), + views.HelpHTML(err.Error()), + user.FromRequest(rq)), + ) return } @@ -50,7 +66,13 @@ func handlerHelp(w http.ResponseWriter, rq *http.Request) { ast := mycomarkup.BlockTree(ctx) result := mycomarkup.BlocksToHTML(ctx, ast) // TODO: styled output idk - _, _ = io.WriteString(w, result) + w.WriteHeader(http.StatusOK) + _, _ = io.WriteString( + w, + views.BaseHTML("Help", + views.HelpHTML(result), + user.FromRequest(rq)), + ) } // handlerList shows a list of all hyphae in the wiki in random order.