{{block "entry not found" .}}Entry not found{{end}}
+{{block "entry not found invitation" .}}If you want to write this entry by yourself, consider contributing it directly.{{end}}
+ {{end}} +diff --git a/help/help.go b/help/help.go index bc12477..057d3c1 100644 --- a/help/help.go +++ b/help/help.go @@ -5,7 +5,7 @@ import ( "embed" ) -//go:embed en en.myco +//go:embed en en.myco *.html var fs embed.FS // Get determines what help text you need and returns it. The path is a substring from URL, it follows this form: diff --git a/help/view_help.html b/help/view_help.html new file mode 100644 index 0000000..17f1d7f --- /dev/null +++ b/help/view_help.html @@ -0,0 +1,16 @@ +{{define "title"}}Help{{end}} +{{define "body"}} +
{{block "entry not found invitation" .}}If you want to write this entry by yourself, consider contributing it directly.{{end}}
+ {{end}} +{%s lc.Get("help.empty_error_line_1") %}
-{%s lc.Get("help.empty_error_line_2a") %} {%s lc.Get("help.empty_error_link") %} {%s lc.Get("help.empty_error_line_2b") %}
-{% endfunc %} {% func commonScripts() %} {% for _, scriptPath := range cfg.CommonScripts %} diff --git a/views/stuff.qtpl.go b/views/stuff.qtpl.go index 0298658..c0b4e29 100644 --- a/views/stuff.qtpl.go +++ b/views/stuff.qtpl.go @@ -7,174 +7,64 @@ package views //line views/stuff.qtpl:1 import "github.com/bouncepaw/mycorrhiza/cfg" -//line views/stuff.qtpl:2 -import "github.com/bouncepaw/mycorrhiza/l18n" - -//line views/stuff.qtpl:4 +//line views/stuff.qtpl:3 import ( qtio422016 "io" qt422016 "github.com/valyala/quicktemplate" ) -//line views/stuff.qtpl:4 +//line views/stuff.qtpl:3 var ( _ = qtio422016.Copy _ = qt422016.AcquireByteBuffer ) -//line views/stuff.qtpl:4 -func StreamHelp(qw422016 *qt422016.Writer, content, lang string, lc *l18n.Localizer) { -//line views/stuff.qtpl:4 - qw422016.N().S(` -`) -//line views/stuff.qtpl:17 - qw422016.E().S(lc.Get("help.empty_error_line_1")) -//line views/stuff.qtpl:17 - qw422016.N().S(`
-`) -//line views/stuff.qtpl:18 - qw422016.E().S(lc.Get("help.empty_error_line_2a")) -//line views/stuff.qtpl:18 - qw422016.N().S(` `) -//line views/stuff.qtpl:18 - qw422016.E().S(lc.Get("help.empty_error_link")) -//line views/stuff.qtpl:18 - qw422016.N().S(` `) -//line views/stuff.qtpl:18 - qw422016.E().S(lc.Get("help.empty_error_line_2b")) -//line views/stuff.qtpl:18 - qw422016.N().S(`
-`) -//line views/stuff.qtpl:19 -} - -//line views/stuff.qtpl:19 -func WriteHelpEmptyError(qq422016 qtio422016.Writer, lc *l18n.Localizer) { -//line views/stuff.qtpl:19 - qw422016 := qt422016.AcquireWriter(qq422016) -//line views/stuff.qtpl:19 - StreamHelpEmptyError(qw422016, lc) -//line views/stuff.qtpl:19 - qt422016.ReleaseWriter(qw422016) -//line views/stuff.qtpl:19 -} - -//line views/stuff.qtpl:19 -func HelpEmptyError(lc *l18n.Localizer) string { -//line views/stuff.qtpl:19 - qb422016 := qt422016.AcquireByteBuffer() -//line views/stuff.qtpl:19 - WriteHelpEmptyError(qb422016, lc) -//line views/stuff.qtpl:19 - qs422016 := string(qb422016.B) -//line views/stuff.qtpl:19 - qt422016.ReleaseByteBuffer(qb422016) -//line views/stuff.qtpl:19 - return qs422016 -//line views/stuff.qtpl:19 -} - -//line views/stuff.qtpl:21 +//line views/stuff.qtpl:3 func streamcommonScripts(qw422016 *qt422016.Writer) { -//line views/stuff.qtpl:21 +//line views/stuff.qtpl:3 qw422016.N().S(` `) -//line views/stuff.qtpl:22 +//line views/stuff.qtpl:4 for _, scriptPath := range cfg.CommonScripts { -//line views/stuff.qtpl:22 +//line views/stuff.qtpl:4 qw422016.N().S(` `) -//line views/stuff.qtpl:24 +//line views/stuff.qtpl:6 } -//line views/stuff.qtpl:24 +//line views/stuff.qtpl:6 qw422016.N().S(` `) -//line views/stuff.qtpl:25 +//line views/stuff.qtpl:7 } -//line views/stuff.qtpl:25 +//line views/stuff.qtpl:7 func writecommonScripts(qq422016 qtio422016.Writer) { -//line views/stuff.qtpl:25 +//line views/stuff.qtpl:7 qw422016 := qt422016.AcquireWriter(qq422016) -//line views/stuff.qtpl:25 +//line views/stuff.qtpl:7 streamcommonScripts(qw422016) -//line views/stuff.qtpl:25 +//line views/stuff.qtpl:7 qt422016.ReleaseWriter(qw422016) -//line views/stuff.qtpl:25 +//line views/stuff.qtpl:7 } -//line views/stuff.qtpl:25 +//line views/stuff.qtpl:7 func commonScripts() string { -//line views/stuff.qtpl:25 +//line views/stuff.qtpl:7 qb422016 := qt422016.AcquireByteBuffer() -//line views/stuff.qtpl:25 +//line views/stuff.qtpl:7 writecommonScripts(qb422016) -//line views/stuff.qtpl:25 +//line views/stuff.qtpl:7 qs422016 := string(qb422016.B) -//line views/stuff.qtpl:25 +//line views/stuff.qtpl:7 qt422016.ReleaseByteBuffer(qb422016) -//line views/stuff.qtpl:25 +//line views/stuff.qtpl:7 return qs422016 -//line views/stuff.qtpl:25 +//line views/stuff.qtpl:7 } diff --git a/web/help.go b/web/help.go deleted file mode 100644 index 11bccce..0000000 --- a/web/help.go +++ /dev/null @@ -1,80 +0,0 @@ -package web - -// stuff.go is used for meta stuff about the wiki or all hyphae at once. -import ( - "github.com/bouncepaw/mycomarkup/v4" - "github.com/bouncepaw/mycorrhiza/shroom" - "github.com/bouncepaw/mycorrhiza/viewutil" - "io" - "net/http" - "strings" - - "github.com/gorilla/mux" - - "github.com/bouncepaw/mycorrhiza/help" - "github.com/bouncepaw/mycorrhiza/l18n" - "github.com/bouncepaw/mycorrhiza/views" - - "github.com/bouncepaw/mycomarkup/v4/mycocontext" -) - -func initHelp(r *mux.Router) { - r.PathPrefix("/help").HandlerFunc(handlerHelp) -} - -// handlerHelp gets the appropriate documentation or tells you where you (personally) have failed. -func handlerHelp(w http.ResponseWriter, rq *http.Request) { - lc := l18n.FromRequest(rq) - articlePath := strings.TrimPrefix(strings.TrimPrefix(rq.URL.Path, "/help/"), "/help") - // See the history of this file to resurrect the old algorithm that supported multiple languages - lang := "en" - if articlePath == "" { - articlePath = "en" - } - - if !strings.HasPrefix(articlePath, "en") { - w.WriteHeader(http.StatusNotFound) - _, _ = io.WriteString(w, "404 Not found") - return - } - - content, err := help.Get(articlePath) - if err != nil && strings.HasPrefix(err.Error(), "open") { - w.WriteHeader(http.StatusNotFound) - _, _ = io.WriteString( - w, - views.Base( - viewutil.MetaFrom(w, rq), - lc.Get("help.entry_not_found"), - views.Help(views.HelpEmptyError(lc), lang, lc), - ), - ) - return - } - if err != nil { - w.WriteHeader(http.StatusInternalServerError) - _, _ = io.WriteString( - w, - views.Base( - viewutil.MetaFrom(w, rq), - err.Error(), - views.Help(err.Error(), lang, lc), - ), - ) - return - } - - // TODO: change for the function that uses byte array when there is such function in mycomarkup. - ctx, _ := mycocontext.ContextFromStringInput(string(content), shroom.MarkupOptions(articlePath)) - ast := mycomarkup.BlockTree(ctx) - result := mycomarkup.BlocksToHTML(ctx, ast) - w.WriteHeader(http.StatusOK) - _, _ = io.WriteString( - w, - views.Base( - viewutil.MetaFrom(w, rq), - lc.Get("help.title"), - views.Help(result, lang, lc), - ), - ) -} diff --git a/web/web.go b/web/web.go index 845a037..2511e6b 100644 --- a/web/web.go +++ b/web/web.go @@ -4,6 +4,7 @@ package web import ( "github.com/bouncepaw/mycorrhiza/backlinks" "github.com/bouncepaw/mycorrhiza/categories" + "github.com/bouncepaw/mycorrhiza/help" "github.com/bouncepaw/mycorrhiza/misc" "io" "net/http" @@ -47,7 +48,7 @@ func Handler() http.Handler { initReaders(wikiRouter) initMutators(wikiRouter) initHistory(wikiRouter) - initHelp(wikiRouter) + help.InitHandlers(wikiRouter) backlinks.InitHandlers(wikiRouter) categories.InitHandlers(wikiRouter) misc.InitHandlers(wikiRouter)