1
0
forked from x/icebergs
icebergs/core/wiki/image.go
2021-11-01 19:22:12 +08:00

41 lines
1.1 KiB
Go

package wiki
import (
"path"
ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/mdb"
kit "shylinux.com/x/toolkits"
)
func _image_show(m *ice.Message, text string, arg ...string) {
_wiki_template(m, IMAGE, "", _wiki_link(m, IMAGE, text), arg...)
}
const (
PNG = "png"
JPG = "jpg"
JPEG = "jpeg"
)
const IMAGE = "image"
func init() {
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Cmd(mdb.RENDER, mdb.CREATE, PNG, m.Prefix(IMAGE))
}},
IMAGE: {Name: "image url", Help: "图片", Action: map[string]*ice.Action{
mdb.RENDER: {Name: "render", Help: "渲染", Hand: func(m *ice.Message, arg ...string) {
_image_show(m, path.Join(arg[2], arg[1]))
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
_image_show(m, arg[0], arg[1:]...)
}},
}, Configs: map[string]*ice.Config{
IMAGE: {Name: IMAGE, Help: "图片", Value: kit.Data(
kit.MDB_TEMPLATE, `<img {{.OptionTemplate}} title="{{.Option "text"}}" src="{{.Option "text"}}">`,
kit.MDB_PATH, ice.USR_LOCAL_IMAGE,
)},
}})
}