1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-10-30 11:46:16 +00:00

Add the help system

No documentation yet. This branch will eventually be merged into master
This commit is contained in:
Timur Ismagilov 2021-07-11 01:02:16 +05:00
parent 5d45ae67d4
commit 53ae1a6e7a
3 changed files with 47 additions and 0 deletions

7
help/en/index.myco Normal file
View File

@ -0,0 +1,7 @@
This is Mycorrhiza Wiki built-in documentation.
Hope you are doing well ☺️
Here are the topics covered by the documentation:
Thanks for reading!

15
help/help.go Normal file
View File

@ -0,0 +1,15 @@
// Package help contains help messages and the utilities for retrieving them.
package help
import (
"embed"
)
//go:embed en
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:
// <language>/<topic>
func Get(path string) ([]byte, error) {
return fs.ReadFile(path + ".myco")
}

View File

@ -2,6 +2,9 @@ package web
// stuff.go is used for meta stuff about the wiki or all hyphae at once. // stuff.go is used for meta stuff about the wiki or all hyphae at once.
import ( import (
"github.com/bouncepaw/mycomarkup"
"github.com/bouncepaw/mycomarkup/mycocontext"
"github.com/bouncepaw/mycorrhiza/help"
"io" "io"
"log" "log"
"math/rand" "math/rand"
@ -18,6 +21,7 @@ import (
) )
func initStuff() { func initStuff() {
http.HandleFunc("/help/", handlerHelp)
http.HandleFunc("/list/", handlerList) http.HandleFunc("/list/", handlerList)
http.HandleFunc("/reindex/", handlerReindex) http.HandleFunc("/reindex/", handlerReindex)
http.HandleFunc("/update-header-links/", handlerUpdateHeaderLinks) http.HandleFunc("/update-header-links/", handlerUpdateHeaderLinks)
@ -28,6 +32,27 @@ func initStuff() {
}) })
} }
// handlerHelp gets the appropriate documentation or tells you where you (personally) have failed.
func handlerHelp(w http.ResponseWriter, rq *http.Request) {
if shown := user.FromRequest(rq).ShowLockMaybe(w, rq); shown {
return
}
content, err := help.Get(rq.URL.Path[6:]) // Drop /help/
if err != nil {
// TODO: proper error reporting that makes sense
httpErr(w, http.StatusForbidden, cfg.HomeHypha, err.Error(), err.Error())
return
}
// 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))
ast := mycomarkup.BlockTree(ctx)
result := mycomarkup.BlocksToHTML(ctx, ast)
// TODO: styled output idk
_, _ = io.WriteString(w, result)
}
// handlerList shows a list of all hyphae in the wiki in random order. // handlerList shows a list of all hyphae in the wiki in random order.
func handlerList(w http.ResponseWriter, rq *http.Request) { func handlerList(w http.ResponseWriter, rq *http.Request) {
u := user.FromRequest(rq) u := user.FromRequest(rq)