package server import ( "github.com/gomarkdown/markdown" "vultras.su/core/bond" "vultras.su/core/bond/contents" "vultras.su/util/pp" "path/filepath" "os" ) type ServerOptions struct { WikiPath string WebPath string } type Server struct { handler bond.Handler options ServerOptions prep *pp.Preprocessor } func New(opts ServerOptions) *Server { srv := &Server{} srv.handler = makeRootHandler(opts) srv.options = opts srv.prep = pp.NewPp(pp.NewTengo()) return srv } func (srv *Server) Handle(c *bond.Context) { c.Data = ContextData{ Server: srv, } srv.handler.Handle(c) } func (srv *Server) ProcessPmd(pth string, bts []byte) ([]byte, error) { prep, err := srv.prep.Process(pth, string(bts)) if err != nil { return nil, err } return []byte(prep), nil } func (srv *Server) ProcessToHtml(bts []byte) ([]byte, error) { html := markdown.ToHTML(bts, nil, nil) ret := append([]byte(htmlHead), html...) return append(ret, []byte(htmlFooter)...), nil } func (srv *Server) wikiFilePath(pth string) string { if pth == "/" || pth == "" { return srv.options.WikiPath + "/index.pmd" } if pth[len(pth)-1] == '/' { pth += "index" } return filepath.FromSlash( srv.options.WikiPath + "/" + pth + ".pmd", ) } const htmlHead = `