package main
import (
"fmt"
"log"
"net/http"
"os"
"path/filepath"
"regexp"
"github.com/bouncepaw/mycorrhiza/history"
"github.com/bouncepaw/mycorrhiza/util"
)
// WikiDir is a rooted path to the wiki storage directory.
var WikiDir string
// HyphaPattern is a pattern which all hyphae must match. Not used currently.
var HyphaPattern = regexp.MustCompile(`[^?!:#@><*|"\'&%]+`)
// HyphaStorage is a mapping between canonical hypha names and their meta information.
var HyphaStorage = make(map[string]*HyphaData)
// IterateHyphaNamesWith is a closure to be passed to subpackages to let them iterate all hypha names read-only.
func IterateHyphaNamesWith(f func(string)) {
for hyphaName, _ := range HyphaStorage {
f(hyphaName)
}
}
// HttpErr is used by many handlers to signal errors in a compact way.
func HttpErr(w http.ResponseWriter, status int, name, title, errMsg string) {
log.Println(errMsg, "for", name)
w.Header().Set("Content-Type", "text/html;charset=utf-8")
w.WriteHeader(status)
fmt.Fprint(w, base(title, fmt.Sprintf(
`
`,
errMsg, name)))
}
// shorterPath is used by handlerList to display shorter path to the files. It simply strips WikiDir. It was moved to util package, this is an alias. TODO: demolish.
var shorterPath = util.ShorterPath
// Show all hyphae
func handlerList(w http.ResponseWriter, rq *http.Request) {
log.Println(rq.URL)
w.Header().Set("Content-Type", "text/html;charset=utf-8")
w.WriteHeader(http.StatusOK)
buf := `
List of pages
Name
Text path
Text type
Binary path
Binary type
`
for name, data := range HyphaStorage {
buf += fmt.Sprintf(`