1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2025-11-19 00:25:20 +00:00

Write the whitelist help article and fix some help bugs

The bugs were introduced by the new routing system...
This commit is contained in:
Timur Ismagilov
2021-07-24 16:30:28 +05:00
parent 6241350e8b
commit 87e0045d80
5 changed files with 204 additions and 170 deletions

View File

@@ -24,7 +24,7 @@ import (
)
func initStuff(r *mux.Router) {
r.PathPrefix("/help/").HandlerFunc(handlerHelp)
r.PathPrefix("/help").HandlerFunc(handlerHelp)
r.HandleFunc("/list", handlerList)
r.HandleFunc("/reindex", handlerReindex)
r.HandleFunc("/update-header-links", handlerUpdateHeaderLinks)
@@ -37,7 +37,11 @@ func initStuff(r *mux.Router) {
// handlerHelp gets the appropriate documentation or tells you where you (personally) have failed.
func handlerHelp(w http.ResponseWriter, rq *http.Request) {
content, err := help.Get(rq.URL.Path[6:]) // Drop /help/
articlePath := strings.TrimPrefix(strings.TrimPrefix(rq.URL.Path, "/help/"), "/help")
if articlePath == "" {
articlePath = "en"
}
content, err := help.Get(articlePath)
if err != nil && strings.HasPrefix(err.Error(), "open") {
w.WriteHeader(http.StatusNotFound)
_, _ = io.WriteString(
@@ -60,10 +64,9 @@ func handlerHelp(w http.ResponseWriter, rq *http.Request) {
}
// TODO: change for the function that uses byte array when there is such function in mycomarkup.
ctx, _ := mycocontext.ContextFromStringInput(rq.URL.Path[1:3], string(content))
ctx, _ := mycocontext.ContextFromStringInput(articlePath, string(content))
ast := mycomarkup.BlockTree(ctx)
result := mycomarkup.BlocksToHTML(ctx, ast)
// TODO: styled output idk
w.WriteHeader(http.StatusOK)
_, _ = io.WriteString(
w,