mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-26 01:04:06 +08:00
72 lines
2.5 KiB
Go
72 lines
2.5 KiB
Go
package wiki
|
|
|
|
import (
|
|
"github.com/gomarkdown/markdown"
|
|
|
|
"contexts/ctx"
|
|
"contexts/web"
|
|
|
|
"bytes"
|
|
"html/template"
|
|
"path"
|
|
)
|
|
|
|
var Index = &ctx.Context{Name: "wiki", Help: "文档中心",
|
|
Caches: map[string]*ctx.Cache{},
|
|
Configs: map[string]*ctx.Config{
|
|
"login": &ctx.Config{Name: "login", Value: map[string]interface{}{"check": "false"}, Help: "用户登录"},
|
|
"componet": &ctx.Config{Name: "componet", Value: map[string]interface{}{
|
|
"index": []interface{}{
|
|
map[string]interface{}{"name": "wiki",
|
|
"tmpl": "head", "metas": []interface{}{map[string]interface{}{
|
|
"name": "viewport", "content": "width=device-width, initial-scale=0.7, user-scalable=no",
|
|
}}, "favicon": "favicon.ico", "styles": []interface{}{
|
|
"example.css", "wiki.css",
|
|
}},
|
|
map[string]interface{}{"name": "header",
|
|
"tmpl": "fieldset", "view": "Header", "init": "initHeader",
|
|
},
|
|
map[string]interface{}{"name": "tree",
|
|
"tmpl": "fieldset", "view": "Tree", "init": "initTree",
|
|
"ctx": "web.wiki", "cmd": "tree",
|
|
},
|
|
map[string]interface{}{"name": "text",
|
|
"tmpl": "fieldset", "view": "Text", "init": "initText",
|
|
"ctx": "web.wiki", "cmd": "text",
|
|
},
|
|
map[string]interface{}{"name": "footer",
|
|
"tmpl": "fieldset", "view": "Footer", "init": "initFooter",
|
|
},
|
|
map[string]interface{}{"name": "tail",
|
|
"tmpl": "tail", "scripts": []interface{}{
|
|
"toolkit.js", "context.js", "example.js", "wiki.js",
|
|
},
|
|
},
|
|
},
|
|
}, Help: "组件列表"},
|
|
|
|
"level": &ctx.Config{Name: "level", Value: "local/wiki/自然/编程", Help: "路由数量"},
|
|
"class": &ctx.Config{Name: "class", Value: "", Help: "路由数量"},
|
|
"favor": &ctx.Config{Name: "favor", Value: "index.md", Help: "路由数量"},
|
|
},
|
|
Commands: map[string]*ctx.Command{
|
|
"tree": &ctx.Command{Name: "tree", Help: "目录", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
|
m.Cmdy("nfs.dir", path.Join(m.Confx("level"), m.Confx("class", arg, 0)),
|
|
"time", "size", "line", "file", "dir_sort", "time", "time_r")
|
|
return
|
|
}},
|
|
"text": &ctx.Command{Name: "text", Help: "文章", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
|
which := m.Cmdx("nfs.path", path.Join(m.Confx("level"), m.Confx("class", arg, 1), m.Confx("favor", arg, 0)))
|
|
|
|
buffer := bytes.NewBuffer([]byte{})
|
|
template.Must(template.ParseFiles(which)).Funcs(ctx.CGI).Execute(buffer, m)
|
|
m.Echo(string(markdown.ToHTML(buffer.Bytes(), nil, nil)))
|
|
return
|
|
}},
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
web.Index.Register(Index, &web.WEB{Context: Index})
|
|
}
|