1
0
forked from x/icebergs
icebergs/core/wiki/image.go
2022-07-09 20:13:21 +08:00

47 lines
1.2 KiB
Go

package wiki
import (
"path"
ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs"
kit "shylinux.com/x/toolkits"
)
func _image_show(m *ice.Message, text string) {
_wiki_template(m, IMAGE, "", _wiki_link(m, IMAGE, text))
}
const (
IMG = "img"
PNG = "png"
JPG = "jpg"
JPEG = "jpeg"
)
const IMAGE = "image"
func init() {
Index.Merge(&ice.Context{Commands: ice.Commands{
IMAGE: {Name: "image url height auto", Help: "图片", Actions: ice.Actions{
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
m.Cmd(mdb.RENDER, mdb.CREATE, PNG, m.PrefixKey())
}},
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, arg ...string) {
if len(arg) == 0 {
return
}
m.Option("height", kit.Select("", arg, 1))
_image_show(m, arg[0])
}},
}, Configs: ice.Configs{
IMAGE: {Name: IMAGE, Help: "图片", Value: kit.Data(
nfs.TEMPLATE, `<img {{.OptionTemplate}} title="{{.Option "text"}}" src="{{.Option "text"}}" height="{{.Option "height"}}">`,
nfs.PATH, ice.USR_LOCAL_IMAGE,
)},
}})
}